Skip to content

Commit ec23e96

Browse files
committed
Com_sprintf: revert to int size argument
1 parent e838040 commit ec23e96

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/client/cl_demos_auto.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ char *demoAutoFormat(const char* name) {
2828
const char *format;
2929
qboolean haveTag = qfalse;
3030
static char outBuf[512];
31-
size_t outIndex = 0;
32-
size_t outLeft = sizeof(outBuf) - 1;
31+
int outIndex = 0;
32+
int outLeft = sizeof(outBuf) - 1;
3333

3434
int t = 0;
3535
char timeStamps[MAX_QPATH] = "";

src/qcommon/q_shared.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,16 +1056,20 @@ size_t Q_vsnprintf(char *str, size_t size, const char *format, va_list ap) {
10561056
}
10571057
#endif
10581058

1059-
void QDECL Com_sprintf(char *dest, size_t size, const char *fmt, ...) {
1059+
void QDECL Com_sprintf(char *dest, int size, const char *fmt, ...) {
10601060
size_t len;
10611061
va_list argptr;
10621062

1063+
if (size < 1) {
1064+
Com_Error(ERR_FATAL, "Com_sprintf: size < 1");
1065+
}
1066+
10631067
va_start(argptr, fmt);
10641068
len = Q_vsnprintf(dest, size, fmt, argptr);
10651069
va_end(argptr);
10661070

1067-
if (len >= size) {
1068-
Com_Printf("Com_sprintf: overflow of %zu in %zu\n", len, size);
1071+
if (len >= (size_t)size) {
1072+
Com_Printf("Com_sprintf: overflow of %zu in %d\n", len, size);
10691073
}
10701074
}
10711075

src/qcommon/q_shared.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ void Parse1DMatrix (const char **buf_p, int x, float *m);
10241024
void Parse2DMatrix (const char **buf_p, int y, int x, float *m);
10251025
void Parse3DMatrix (const char **buf_p, int z, int y, int x, float *m);
10261026

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

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

0 commit comments

Comments
 (0)