Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: fix formatting of large messages #3974

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/gb/gb.h
Original file line number Diff line number Diff line change
Expand Up @@ -5882,7 +5882,7 @@ gb_internal isize gb__print_string(char *text, isize max_len, gbprivFmtInfo *inf
len = info->precision < len ? info->precision : len;
}

res += gb_strlcpy(text, str, len);
res += gb_strlcpy(text, str, gb_min(len, max_len));

if (info->width > res) {
isize padding = info->width - len;
Expand Down Expand Up @@ -6037,14 +6037,16 @@ gb_internal isize gb__print_f64(char *text, isize max_len, gbprivFmtInfo *info,
gb_no_inline isize gb_snprintf_va(char *text, isize max_len, char const *fmt, va_list va) {
char const *text_begin = text;
isize remaining = max_len, res;
remaining--;

while (*fmt) {
while (*fmt && remaining) {
gbprivFmtInfo info = {0};
isize len = 0;
info.precision = -1;

while (*fmt && *fmt != '%' && remaining) {
*text++ = *fmt++;
remaining--;
}

if (*fmt == '%') {
Expand Down Expand Up @@ -6210,15 +6212,15 @@ gb_no_inline isize gb_snprintf_va(char *text, isize max_len, char const *fmt, va

text += len;
if (len >= remaining) {
remaining = gb_min(remaining, 1);
remaining = 0;
} else {
remaining -= len;
}
}

*text++ = '\0';
res = (text - text_begin);
return (res >= max_len || res < 0) ? -1 : res;
return (res > max_len || res < 0) ? -1 : res;
}


Expand Down