Skip to content

Commit

Permalink
Com_sprintf: revert to int size argument
Browse files Browse the repository at this point in the history
  • Loading branch information
aufau committed Feb 7, 2018
1 parent e838040 commit ec23e96
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/client/cl_demos_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ char *demoAutoFormat(const char* name) {
const char *format;
qboolean haveTag = qfalse;
static char outBuf[512];
size_t outIndex = 0;
size_t outLeft = sizeof(outBuf) - 1;
int outIndex = 0;
int outLeft = sizeof(outBuf) - 1;

int t = 0;
char timeStamps[MAX_QPATH] = "";
Expand Down
10 changes: 7 additions & 3 deletions src/qcommon/q_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,16 +1056,20 @@ size_t Q_vsnprintf(char *str, size_t size, const char *format, va_list ap) {
}
#endif

void QDECL Com_sprintf(char *dest, size_t size, const char *fmt, ...) {
void QDECL Com_sprintf(char *dest, int size, const char *fmt, ...) {
size_t len;
va_list argptr;

if (size < 1) {
Com_Error(ERR_FATAL, "Com_sprintf: size < 1");
}

va_start(argptr, fmt);
len = Q_vsnprintf(dest, size, fmt, argptr);
va_end(argptr);

if (len >= size) {
Com_Printf("Com_sprintf: overflow of %zu in %zu\n", len, size);
if (len >= (size_t)size) {
Com_Printf("Com_sprintf: overflow of %zu in %d\n", len, size);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/qcommon/q_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ void Parse1DMatrix (const char **buf_p, int x, float *m);
void Parse2DMatrix (const char **buf_p, int y, int x, float *m);
void Parse3DMatrix (const char **buf_p, int z, int y, int x, float *m);

void QDECL Com_sprintf (char *dest, size_t size, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));

#if defined(_MSC_VER) && _MSC_VER < 1900
size_t Q_vsnprintf(char *str, size_t size, const char *format, va_list ap);
Expand Down

0 comments on commit ec23e96

Please sign in to comment.