Skip to content

Commit

Permalink
sprintf: hopefully fix the snprintf handling of \0
Browse files Browse the repository at this point in the history
  • Loading branch information
EtchedPixels committed Feb 7, 2025
1 parent faab597 commit 6b8aca7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Library/libs/sprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ int snprintf(char *sp, size_t size, const char *fmt, ...)
int rv;
unsigned char *p = string->bufpos;

if (size == 0)
return 0;

va_start(ptr, fmt);
string->bufpos = (unsigned char *) sp;
rv = _vfnprintf(string, size, fmt, ptr);
rv = _vfnprintf(string, size - 1, fmt, ptr);
va_end(ptr);
*(string->bufpos) = 0;

Expand All @@ -82,8 +85,11 @@ int vsnprintf(char *sp, size_t size, const char *fmt, va_list ptr)
int rv;
unsigned char *p = string->bufpos;

if (size == 0)
return 0;

string->bufpos = (unsigned char *) sp;
rv = _vfnprintf(string, size, fmt, ptr);
rv = _vfnprintf(string, size - 1, fmt, ptr);
*(string->bufpos) = 0;

string->bufpos = p;
Expand Down

0 comments on commit 6b8aca7

Please sign in to comment.