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

use vsprintf_s on Windows and vsnprintf elsewhere instead of vsprintf #1121

Merged
merged 2 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion c/makeotf/makeotf_lib/source/hotconv/cmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static void CDECL cmapMsg(hotCtx g, int msgType, char *fmt, ...) {
char msg[1024];

va_start(ap, fmt);
vsprintf(msgVar, fmt, ap);
VSPRINTF_S(msgVar, sizeof(msgVar), fmt, ap);
va_end(ap);
sprintf(msg, "cmap{plat=%u,script=%u,lang=%u}: %s", h->platformId,
h->scriptId, h->language, msgVar);
Expand Down
4 changes: 2 additions & 2 deletions c/makeotf/makeotf_lib/source/hotconv/feat.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ static void CDECL zzerrVA(char *fmt, ...) {
char msg[1024];

va_start(ap, fmt);
vsprintf(msg, fmt, ap);
VSPRINTF_S(msg, sizeof(msg), fmt, ap);
va_end(ap);
zzerr(msg);
}
Expand All @@ -458,7 +458,7 @@ static void CDECL featMsg(int msgType, char *fmt, ...) {
char msg[1024];

va_start(ap, fmt);
vsprintf(msgVar, fmt, ap);
VSPRINTF_S(msgVar, sizeof(msgVar), fmt, ap);
va_end(ap);
sprintf(msg, "%s [%s %d]", msgVar, INCL.file, zzline);

Expand Down
6 changes: 5 additions & 1 deletion c/makeotf/makeotf_lib/source/hotconv/hot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1851,9 +1851,13 @@ void CDECL hotMsg(hotCtx g, int level, char *fmt, ...) {
#define MAX_NOTE_LEN 1024
char message[MAX_NOTE_LEN + 1024];
char *p;
size_t p_size;

p_size = sizeof(message);
if ((g->font.FontName.cnt != 0) && (lenName < MAX_NOTE_LEN)) {
sprintf(message, "<%s> ", g->font.FontName.array);
p = &message[lenName];
p_size -= lenName;
} else {
p = message;
}
Expand All @@ -1867,7 +1871,7 @@ void CDECL hotMsg(hotCtx g, int level, char *fmt, ...) {
}

va_start(ap, fmt);
vsprintf(p, fmt, ap);
VSPRINTF_S(p, p_size, fmt, ap);
va_end(ap);
g->cb.message(g->cb.ctx, level, message);
}
Expand Down
2 changes: 1 addition & 1 deletion c/makeotf/makeotf_lib/source/hotconv/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ static void CDECL CMapMsg(mapCtx h, int msgType, char *fmt, ...) {
char msg[2048];

va_start(ap, fmt);
vsprintf(msgVar, fmt, ap);
VSPRINTF_S(msgVar, sizeof(msgVar), fmt, ap);
va_end(ap);
sprintf(msg, "%s [%s]", msgVar, h->ps.cb.psId ? h->ps.cb.psId(h->ps.cb.ctx) : "");

Expand Down
4 changes: 2 additions & 2 deletions c/makeotf/makeotf_lib/source/pstoken/pstoken.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ void CDECL psWarning(psCtx h, char *fmt, ...) {

/* Format message */
va_start(ap, fmt);
vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);

if (h->cb.psId != NULL) {
/* Append source data id */
Expand All @@ -816,7 +816,7 @@ void CDECL psFatal(psCtx h, char *fmt, ...) {
char text[513];

va_start(ap, fmt);
vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);

if (h->cb.psId != NULL) {
/* Append source data id */
Expand Down
6 changes: 3 additions & 3 deletions c/makeotf/makeotf_lib/source/typecomp/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void CDECL parseWarning(tcCtx g, char *fmt, ...) {

/* Format and report message */
va_start(ap, fmt);
vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);
g->cb.message(g->cb.ctx, tcWARNING, text);
va_end(ap);
}
Expand All @@ -404,7 +404,7 @@ void CDECL parseNewGlyphReport(tcCtx g, char *fmt, ...) {

/* Format and report message */
va_start(ap, fmt);
vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);
g->cb.message(g->cb.ctx, tcNOTE, text);
va_end(ap);
}
Expand All @@ -423,7 +423,7 @@ void CDECL parseFatal(tcCtx g, char *fmt, ...) {

/* Format and report message */
va_start(ap, fmt);
vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);
g->cb.message(ctx, tcFATAL, text);
va_end(ap);
}
Expand Down
6 changes: 3 additions & 3 deletions c/makeotf/makeotf_lib/source/typecomp/tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ void CDECL tcFatal(tcCtx g, char *fmt, ...) {
va_list ap;

va_start(ap, fmt);
vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);

if (g->cb.psId != NULL) {
/* Append source data id */
Expand All @@ -1081,7 +1081,7 @@ void CDECL tcWarning(tcCtx g, char *fmt, ...) {
va_list ap;

va_start(ap, fmt);
vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);

if (g->cb.psId != NULL) {
/* Append source data id */
Expand All @@ -1101,7 +1101,7 @@ void CDECL tcNote(tcCtx g, char *fmt, ...) {
va_list ap;

va_start(ap, fmt);
vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);

if (g->cb.psId != NULL) {
/* Append source data id */
Expand Down
4 changes: 2 additions & 2 deletions c/makeotf/source/cbpriv.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void cbFatal(cbCtx h, char *fmt, ...) {
char text[512];
va_list ap;
va_start(ap, fmt);
vsnprintf(text, sizeof(text), fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);
message(h, hotFATAL, text);
va_end(ap);
if (!KeepGoing) {
Expand All @@ -31,7 +31,7 @@ void cbWarning(cbCtx h, char *fmt, ...) {
char text[512];
va_list ap;
va_start(ap, fmt);
vsnprintf(text, sizeof(text), fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);
message(h, hotWARNING, text);
va_end(ap);
}
2 changes: 1 addition & 1 deletion c/public/lib/api/ctlshare.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ enum {
#define SPRINTF_S(b, l, f, ...) sprintf(b, f, ##__VA_ARGS__)
#endif
#ifndef VSPRINTF_S
#define VSPRINTF_S(b, l, f, ...) vsprintf(b, f, ##__VA_ARGS__)
#define VSPRINTF_S vsnprintf
#endif
#ifndef SSCANF_S
#define SSCANF_S sscanf
Expand Down
3 changes: 1 addition & 2 deletions c/public/lib/source/cffwrite/cffwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -2281,12 +2281,11 @@ void cfwFree(cfwCtx g) {
/* Write message to debug stream from va_list. */
static void vmessage(cfwCtx g, char *fmt, va_list ap) {
char text[500];
const size_t textLen = sizeof(text);

if (g->stm.dbg == NULL) {
return; /* Debug stream not available */
}
VSPRINTF_S(text, textLen, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);
(void)g->cb.stm.write(&g->cb.stm, g->stm.dbg, strlen(text), text);
}

Expand Down
6 changes: 3 additions & 3 deletions c/public/lib/source/pdfwrite/pdfwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ static void CTL_CDECL dstPrint(pdwCtx h, char *fmt, ...) {
char buf[500];
va_list ap;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
VSPRINTF_S(buf, sizeof(buf), fmt, ap);
dstWrite(h, strlen(buf), buf);
va_end(ap);
}
Expand Down Expand Up @@ -541,7 +541,7 @@ static void CTL_CDECL stmPrint(pdwCtx h, long iStm, char *fmt, ...) {
long length;
va_list ap;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
VSPRINTF_S(buf, sizeof(buf), fmt, ap);
va_end(ap);
length = (long)strlen(buf);
memcpy(dnaEXTEND(h->stms[iStm], length), buf, length);
Expand Down Expand Up @@ -617,7 +617,7 @@ static void CTL_CDECL textShow(pdwCtx h, char *fmt, ...) {

/* Format text */
va_start(ap, fmt);
vsprintf(src, fmt, ap);
VSPRINTF_S(src, sizeof(src), fmt, ap);
va_end(ap);

/* Double backslashes */
Expand Down
2 changes: 1 addition & 1 deletion c/public/lib/source/svgwrite/svgwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static void CTL_CDECL writeFmt(svwCtx h, char *fmt, ...) {
char buf[200];
va_list ap;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
VSPRINTF_S(buf, sizeof(buf), fmt, ap);
writeStr(h, buf);
va_end(ap);
}
Expand Down
2 changes: 1 addition & 1 deletion c/public/lib/source/svread/svread.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void vmessage(svrCtx h, char *fmt, va_list ap) {
if (h->stm.dbg == NULL)
return; /* Debug stream not available */

vsnprintf(text, BUFSIZ, fmt, ap);
VSPRINTF_S(text, BUFSIZ, fmt, ap);
(void)h->cb.stm.write(&h->cb.stm, h->stm.dbg, strlen(text), text);
}

Expand Down
2 changes: 1 addition & 1 deletion c/public/lib/source/t1read/t1read.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static void vmessage(t1rCtx h, char *fmt, va_list ap) {
if (h->stm.dbg == NULL)
return; /* Debug stream not available */

vsnprintf(text, 500, fmt, ap);
VSPRINTF_S(text, 500, fmt, ap);
(void)h->cb.stm.write(&h->cb.stm, h->stm.dbg, strlen(text), text);
}

Expand Down
2 changes: 1 addition & 1 deletion c/public/lib/source/t1write/t1write.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static void CTL_CDECL writeFmt(t1wCtx h, char *fmt, ...) {
char buf[200];
va_list ap;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
VSPRINTF_S(buf, sizeof(buf), fmt, ap);
writeStr(h, buf);
va_end(ap);
}
Expand Down
2 changes: 1 addition & 1 deletion c/public/lib/source/ttread/ttread.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ static void vmessage(ttrCtx h, char *fmt, va_list ap) {
if (h->stm.dbg == NULL)
return; /* Debug stream not available */

vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);
(void)h->cb.stm.write(&h->cb.stm, h->stm.dbg, strlen(text), text);
}

Expand Down
2 changes: 1 addition & 1 deletion c/public/lib/source/uforead/uforead.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static void vmessage(ufoCtx h, char* fmt, va_list ap) {
if (h->stm.dbg == NULL)
return; /* Debug stream not available */

vsprintf(text, fmt, ap);
VSPRINTF_S(text, sizeof(text), fmt, ap);
(void)h->cb.stm.write(&h->cb.stm, h->stm.dbg, strlen(text), text);
}

Expand Down