Apple Clang complains about sprintf. Use snprintf instead. (#2862)

Co-authored-by: Your Name <you@example.com>
pull/2866/head
pfeatherstone 1 year ago committed by GitHub
parent c53ff25952
commit dad29bfae7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1614,9 +1614,9 @@ namespace dlib
char **mlist; char **mlist;
int mcount; int mcount;
char *def_str; char *def_str;
char fontset[256]; char fontset[256] = {0};
const long native_font_height = 12; const long native_font_height = 12;
sprintf(fontset, "-*-*-medium-r-normal--%lu-*-*-*-", native_font_height); snprintf(fontset, sizeof(fontset), "-*-*-medium-r-normal--%lu-*-*-*-", native_font_height);
x11_stuff.fs = XCreateFontSet(x11_stuff.globals->disp, fontset, &mlist, &mcount, &def_str); x11_stuff.fs = XCreateFontSet(x11_stuff.globals->disp, fontset, &mlist, &mcount, &def_str);
xpoint.x = 0; xpoint.x = 0;
xpoint.y = 0; xpoint.y = 0;

@ -345,13 +345,12 @@ namespace nativefont
cmap = DefaultColormap(d, DefaultScreen(d)); cmap = DefaultColormap(d, DefaultScreen(d));
} }
char fontset[256]; char fontset[256] = {0};
{ {
char *p = fontset; int offset = snprintf(fontset, sizeof(fontset), "-*-*-%s-%c-normal--%d-*-*-*-%c",
p += sprintf(fontset, "-*-*-%s-%c-normal--%d-*-*-*-%c",
bold ? "bold" : "medium", italic ? 'i' : 'r', height_want, fixed ? 'c' : 'p'); bold ? "bold" : "medium", italic ? 'i' : 'r', height_want, fixed ? 'c' : 'p');
if (fixed){ if (fixed){
sprintf(p, ",-*-*-%s-%c-normal--%d-*-*-*-m", snprintf(&fontset[offset], sizeof(fontset) - offset, ",-*-*-%s-%c-normal--%d-*-*-*-m",
bold ? "bold" : "medium", italic ? 'i' : 'r', height_want); bold ? "bold" : "medium", italic ? 'i' : 'r', height_want);
} }
} }

@ -119,7 +119,7 @@ namespace dlib
#ifdef __WXMSW__ #ifdef __WXMSW__
::ltoa(header_value, buf, 10); ::ltoa(header_value, buf, 10);
#else #else
sprintf(buf, "%ld", header_value); snprintf(buf, sizeof(buf), "%ld", header_value);
#endif #endif
set_header(header_name, buf); set_header(header_name, buf);
} }
@ -154,7 +154,7 @@ namespace dlib
#ifdef __WXMSW__ #ifdef __WXMSW__
::ltoa(cookie_value, buf, 10); ::ltoa(cookie_value, buf, 10);
#else #else
sprintf(buf, "%ld", cookie_value); snprintf(buf, sizeof(buf), "%ld", cookie_value);
#endif #endif
set_cookie(cookie_name, buf); set_cookie(cookie_name, buf);
} }

Loading…
Cancel
Save