Skip to content

Commit

Permalink
Use size_t as len type for xSnprintf
Browse files Browse the repository at this point in the history
Like the C snprintf function
  • Loading branch information
cgzones authored and BenBE committed Dec 6, 2020
1 parent 3d15ba5 commit d9224c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions XUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ int xAsprintf(char** strp, const char* fmt, ...) {
return r;
}

int xSnprintf(char* buf, int len, const char* fmt, ...) {
int xSnprintf(char* buf, size_t len, const char* fmt, ...) {
va_list vl;
va_start(vl, fmt);
int n = vsnprintf(buf, len, fmt, vl);
va_end(vl);

if (n < 0 || n >= len) {
if (n < 0 || (size_t)n >= len) {
fail();
}

Expand Down
2 changes: 1 addition & 1 deletion XUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ATTR_FORMAT(printf, 2, 3)
int xAsprintf(char** strp, const char* fmt, ...);

ATTR_FORMAT(printf, 3, 4)
int xSnprintf(char* buf, int len, const char* fmt, ...);
int xSnprintf(char* buf, size_t len, const char* fmt, ...);

char* xStrdup(const char* str) ATTR_NONNULL;

Expand Down

0 comments on commit d9224c6

Please sign in to comment.