diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-09-26 16:12:18 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-09-26 16:12:18 +0200 |
| commit | 2ffd4e4f1af16b17a286ff354603a717f5d828a5 (patch) | |
| tree | 99e2d4a7e2fde8e3abb027eb687901440750ee00 /src/drivers | |
| parent | 53d9614adbb728fc4db983c9bb817c6eea870994 (diff) | |
Replace all calls to sprintf() by calls to snprintf().
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx | 4 | ||||
| -rw-r--r-- | src/drivers/Darwin/Fl_Darwin_System_Driver.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/Posix/Fl_Posix_Printer_Driver.cxx | 8 | ||||
| -rw-r--r-- | src/drivers/Posix/Fl_Posix_System_Driver.cxx | 14 | ||||
| -rw-r--r-- | src/drivers/PostScript/Fl_PostScript.cxx | 4 | ||||
| -rw-r--r-- | src/drivers/SVG/Fl_SVG_File_Surface.cxx | 22 | ||||
| -rw-r--r-- | src/drivers/Unix/Fl_Unix_System_Driver.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx | 6 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx | 2 |
12 files changed, 36 insertions, 34 deletions
diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx index e601df142..3d61bd64c 100644 --- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx +++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx @@ -1025,7 +1025,7 @@ Fl_Font Fl_Cairo_Graphics_Driver::set_fonts(const char* /*pattern_name*/) // build the font's FLTK name l += strlen(p) + 2; char *q = new char[l]; - sprintf(q, "%s %s", fam_name, p); + snprintf(q, l, "%s %s", fam_name, p); Fl::set_font((Fl_Font)(count++ + FL_FREE_FONT), q); } /*g_*/free(faces); // glib source code shows that g_free is equivalent to free @@ -1098,7 +1098,7 @@ Fl_Cairo_Font_Descriptor::Fl_Cairo_Font_Descriptor(const char* name, Fl_Fontsize strcpy(string, name); // The factor of 0.75 below gives cairo-produced text the same size as // Xft-produced text for the same FLTK font size. - sprintf(string + strlen(string), " %d", int(size * 0.75 + 0.5) ); + snprintf(string + strlen(string), 10, " %d", int(size * 0.75 + 0.5) ); //A PangoFontDescription describes a font in an implementation-independent manner. fontref = pango_font_description_from_string(string); delete[] string; diff --git a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx index 2c4c5a34b..bda6667e8 100644 --- a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx +++ b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx @@ -268,7 +268,7 @@ void Fl_Darwin_System_Driver::newUUID(char *uuidBuffer) { CFUUIDRef theUUID = CFUUIDCreate(NULL); CFUUIDBytes b = CFUUIDGetUUIDBytes(theUUID); - sprintf(uuidBuffer, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", + snprintf(uuidBuffer, 36+1, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", b.byte0, b.byte1, b.byte2, b.byte3, b.byte4, b.byte5, b.byte6, b.byte7, b.byte8, b.byte9, b.byte10, b.byte11, b.byte12, b.byte13, b.byte14, b.byte15); CFRelease(theUUID); diff --git a/src/drivers/Posix/Fl_Posix_Printer_Driver.cxx b/src/drivers/Posix/Fl_Posix_Printer_Driver.cxx index a81596d5d..653ab4a9a 100644 --- a/src/drivers/Posix/Fl_Posix_Printer_Driver.cxx +++ b/src/drivers/Posix/Fl_Posix_Printer_Driver.cxx @@ -112,7 +112,7 @@ int Fl_GTK_Printer_Driver::begin_job(int pagecount, int *firstpage, int *lastpag GtkPrintSettings *psettings = CALL_GTK(gtk_print_unix_dialog_get_settings)(pdialog); //2.10 CALL_GTK(gtk_print_settings_set)(psettings, "output-file-format", "ps"); //2.10 char line[FL_PATH_MAX + 20], cwd[FL_PATH_MAX]; - sprintf(line, "file://%s/FLTK.ps", fl_getcwd(cwd, FL_PATH_MAX)); + snprintf(line, FL_PATH_MAX + 20, "file://%s/FLTK.ps", fl_getcwd(cwd, FL_PATH_MAX)); CALL_GTK(gtk_print_settings_set)(psettings, "output-uri", line); //2.10 CALL_GTK(gtk_print_unix_dialog_set_settings)(pdialog, psettings); //2.10 CALL_GTK(g_object_unref)(psettings); @@ -160,7 +160,7 @@ int Fl_GTK_Printer_Driver::begin_job(int pagecount, int *firstpage, int *lastpag response_id = GTK_RESPONSE_NONE + GTK_RESPONSE_OK + 1; if (perr_message) { *perr_message = new char[strlen(line)+50]; - sprintf(*perr_message, "Can't open output file %s", line); + snprintf(*perr_message, strlen(line)+50, "Can't open output file %s", line); } } } else if ( CALL_GTK(gtk_printer_accepts_ps)(gprinter) && //2.10 @@ -176,7 +176,7 @@ int Fl_GTK_Printer_Driver::begin_job(int pagecount, int *firstpage, int *lastpag response_id = GTK_RESPONSE_NONE + GTK_RESPONSE_OK + 1; if (perr_message) { *perr_message = new char[strlen(tmpfilename)+50]; - sprintf(*perr_message, "Can't create temporary file %s", tmpfilename); + snprintf(*perr_message, strlen(tmpfilename)+50, "Can't create temporary file %s", tmpfilename); } } } @@ -322,7 +322,7 @@ int Fl_Posix_Printer_Driver::begin_job(int pages, int *firstpage, int *lastpage, if (!ps->output) { if (perr_message) { *perr_message = new char[strlen(command) + 50]; - sprintf(*perr_message, "could not run command: %s", command); + snprintf(*perr_message, strlen(command) + 50, "could not run command: %s", command); } return 2; } diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.cxx b/src/drivers/Posix/Fl_Posix_System_Driver.cxx index 9cb4656af..6e90cb5eb 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.cxx +++ b/src/drivers/Posix/Fl_Posix_System_Driver.cxx @@ -177,16 +177,16 @@ int Fl_Posix_System_Driver::run_program(const char *program, char **argv, char * static void* quadruple_dlopen(const char *libname) { char filename2[FL_PATH_MAX]; - sprintf(filename2, "%s.so", libname); + snprintf(filename2, FL_PATH_MAX, "%s.so", libname); void *ptr = dlopen(filename2, RTLD_LAZY | RTLD_GLOBAL); if (!ptr) { - sprintf(filename2, "%s.so.2", libname); + snprintf(filename2, FL_PATH_MAX, "%s.so.2", libname); ptr = dlopen(filename2, RTLD_LAZY | RTLD_GLOBAL); if (!ptr) { - sprintf(filename2, "%s.so.1", libname); + snprintf(filename2, FL_PATH_MAX, "%s.so.1", libname); ptr = dlopen(filename2, RTLD_LAZY | RTLD_GLOBAL); if (!ptr) { - sprintf(filename2, "%s.so.0", libname); + snprintf(filename2, FL_PATH_MAX, "%s.so.0", libname); ptr = dlopen(filename2, RTLD_LAZY | RTLD_GLOBAL); } } @@ -219,13 +219,13 @@ void *Fl_Posix_System_Driver::dlopen_or_dlsym(const char *lib_name, const char * #ifdef __APPLE_CC__ // allows testing on Darwin + XQuartz + fink if (lib_name) { char path[FL_PATH_MAX]; - sprintf(path, "/opt/X11/lib/%s.dylib", lib_name); + snprintf(path, FL_PATH_MAX, "/opt/X11/lib/%s.dylib", lib_name); lib_address = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); if (!lib_address) { - sprintf(path, "/opt/sw/lib/%s.dylib", lib_name); + snprintf(path, FL_PATH_MAX, "/opt/sw/lib/%s.dylib", lib_name); lib_address = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); if (!lib_address) { - sprintf(path, "/sw/lib/%s.dylib", lib_name); + snprintf(path, FL_PATH_MAX, "/sw/lib/%s.dylib", lib_name); lib_address = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); } } diff --git a/src/drivers/PostScript/Fl_PostScript.cxx b/src/drivers/PostScript/Fl_PostScript.cxx index 8b6dfea9b..0022412e5 100644 --- a/src/drivers/PostScript/Fl_PostScript.cxx +++ b/src/drivers/PostScript/Fl_PostScript.cxx @@ -1503,7 +1503,7 @@ int Fl_PostScript_Graphics_Driver::start_postscript(int pagecount, if (!cairo_) return 1; nPages=0; char feature[250]; - sprintf(feature, "%%%%BeginFeature: *PageSize %s\n<</PageSize[%d %d]>>setpagedevice\n%%%%EndFeature", + snprintf(feature, 250, "%%%%BeginFeature: *PageSize %s\n<</PageSize[%d %d]>>setpagedevice\n%%%%EndFeature", Fl_Paged_Device::page_formats[format].name, Fl_Paged_Device::page_formats[format].width, Fl_Paged_Device::page_formats[format].height); cairo_ps_surface_dsc_comment(cairo_get_target(cairo_), feature); return 0; @@ -1635,7 +1635,7 @@ int Fl_PostScript_File_Device::begin_page (void) #if USE_PANGO cairo_ps_surface_dsc_begin_page_setup(cairo_get_target(ps->cr())); char feature[200]; - sprintf(feature, "%%%%PageOrientation: %s", ps->pw_ > ps->ph_ ? "Landscape" : "Portrait"); + snprintf(feature, 200, "%%%%PageOrientation: %s", ps->pw_ > ps->ph_ ? "Landscape" : "Portrait"); cairo_ps_surface_dsc_comment(cairo_get_target(ps->cr()), feature); if (ps->pw_ > ps->ph_) { cairo_translate(ps->cr(), 0, ps->pw_); diff --git a/src/drivers/SVG/Fl_SVG_File_Surface.cxx b/src/drivers/SVG/Fl_SVG_File_Surface.cxx index 73dfd4aa3..da48219aa 100644 --- a/src/drivers/SVG/Fl_SVG_File_Surface.cxx +++ b/src/drivers/SVG/Fl_SVG_File_Surface.cxx @@ -206,9 +206,11 @@ void Fl_SVG_Graphics_Driver::compute_dasharray(float s, char *dashes) { if (user_dash_array_ && user_dash_array_ != dashes) {free(user_dash_array_); user_dash_array_ = NULL;} if (dashes && *dashes) { if (dasharray_) free(dasharray_); - dasharray_ = (char*)calloc(10*strlen(dashes) + 1, 1); + int array_len = 10*strlen(dashes) + 1; + dasharray_ = (char*)calloc(array_len, 1); for (char *p = dashes; *p; p++) { - sprintf(dasharray_+strlen(dasharray_), "%.3f,", (*p)/s); + int c = snprintf(dasharray_+strlen(dasharray_), array_len, "%.3f,", (*p)/s); + array_len -= c; } dasharray_[strlen(dasharray_) - 1] = 0; if (user_dash_array_ != dashes) user_dash_array_ = fl_strdup(dashes); @@ -228,10 +230,10 @@ void Fl_SVG_Graphics_Driver::compute_dasharray(float s, char *dashes) { float big = (is_flat ? 3*width_/s : width_*2.5f/s); if (dasharray_) free(dasharray_); dasharray_ = (char*)malloc(61); - if (dash_part == FL_DOT) sprintf(dasharray_, "%.3f,%.3f", dot, gap); - else if (dash_part == FL_DASH) sprintf(dasharray_, "%.3f,%.3f", big, gap); - else if (dash_part == FL_DASHDOT) sprintf(dasharray_, "%.3f,%.3f,%.3f,%.3f", big, gap, dot, gap); - else sprintf(dasharray_, "%.3f,%.3f,%.3f,%.3f,%.3f,%.3f", big, gap, dot, gap, dot, gap); + if (dash_part == FL_DOT) snprintf(dasharray_, 61, "%.3f,%.3f", dot, gap); + else if (dash_part == FL_DASH) snprintf(dasharray_, 61, "%.3f,%.3f", big, gap); + else if (dash_part == FL_DASHDOT) snprintf(dasharray_, 61, "%.3f,%.3f,%.3f,%.3f", big, gap, dot, gap); + else snprintf(dasharray_, 61, "%.3f,%.3f,%.3f,%.3f,%.3f,%.3f", big, gap, dot, gap, dot, gap); } } @@ -604,7 +606,7 @@ void Fl_SVG_Graphics_Driver::draw_rgb(Fl_RGB_Image *rgb, int XP, int YP, int WP, char name[24]; bool need_clip = (cx || cy || WP != rgb->w() || HP != rgb->h()); void *p = (void*)*Fl_Graphics_Driver::id(rgb); - if (p) sprintf(name, "FLrgb%p", p); else name[0] = 0; + if (p) snprintf(name, 24, "FLrgb%p", p); else name[0] = 0; if (!p || !last_rgb_name_ || strcmp(name, last_rgb_name_) != 0) { if (*name==0 && need_clip) push_clip(XP, YP, WP, HP); #if defined(HAVE_LIBJPEG) @@ -627,7 +629,7 @@ void Fl_SVG_Graphics_Driver::draw_pixmap(Fl_Pixmap *pxm, int XP, int YP, int WP, char name[24]; bool need_clip = (cx || cy || WP != pxm->w() || HP != pxm->h()); void *p = (void*)*Fl_Graphics_Driver::id(pxm); - if (p) sprintf(name, "FLpx%p", p); else name[0] = 0; + if (p) snprintf(name, 24, "FLpx%p", p); else name[0] = 0; if (!p || !last_rgb_name_ || strcmp(name, last_rgb_name_) != 0) { Fl_RGB_Image *rgb = new Fl_RGB_Image(pxm); if (*name==0 && need_clip) push_clip(XP, YP, WP, HP); @@ -648,7 +650,7 @@ void Fl_SVG_Graphics_Driver::draw_bitmap(Fl_Bitmap *bm, int XP, int YP, int WP, char name[45]; bool need_clip = (cx || cy || WP != bm->w() || HP != bm->h()); void *p = (void*)*Fl_Graphics_Driver::id(bm); - if (p) sprintf(name, "FLbm%p%X", p, fl_color()); else name[0] = 0; + if (p) snprintf(name, 45, "FLbm%p%X", p, fl_color()); else name[0] = 0; if (!p || !last_rgb_name_ || strcmp(name, last_rgb_name_) != 0) { uchar R, G, B; Fl::get_color(fl_color(), R, G, B); @@ -740,7 +742,7 @@ void Fl_SVG_Graphics_Driver::push_clip(int x, int y, int w, int h) { Clip * c=new Clip(); clip_box(x,y,w,h,c->x,c->y,c->w,c->h); c->prev=clip_; - sprintf(c->Id, "FLclip%d", clip_count_++); + snprintf(c->Id, sizeof(c->Id), "FLclip%d", clip_count_++); clip_=c; fprintf(out_, "<clipPath id=\"%s\"><rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/></clipPath><g clip-path=\"url(#%s)\">\n", c->Id, clip_->x , clip_->y , clip_->w, clip_->h, c->Id); diff --git a/src/drivers/Unix/Fl_Unix_System_Driver.cxx b/src/drivers/Unix/Fl_Unix_System_Driver.cxx index 176ad9a07..628307c73 100644 --- a/src/drivers/Unix/Fl_Unix_System_Driver.cxx +++ b/src/drivers/Unix/Fl_Unix_System_Driver.cxx @@ -436,7 +436,7 @@ void Fl_Unix_System_Driver::newUUID(char *uuidBuffer) gethostname(name, 79); memcpy(b+12, name, 4); } - sprintf(uuidBuffer, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", + snprintf(uuidBuffer, 36+1, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]); } diff --git a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx index b8afbc1e1..3f131f301 100644 --- a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx @@ -978,7 +978,7 @@ static Fl_Window *calc_transient_parent(int ¢er_x, int ¢er_y) { static const char *get_prog_name() { pid_t pid = getpid(); char fname[100]; - sprintf(fname, "/proc/%u/cmdline", pid); + snprintf(fname, 100, "/proc/%u/cmdline", pid); FILE *in = fopen(fname, "r"); if (in) { static char line[200]; diff --git a/src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx index a92600d91..56b3c6d4b 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx @@ -129,7 +129,7 @@ int Fl_WinAPI_Printer_Driver::begin_job (int pagecount, int *frompage, int *topa while (srclen > 0 && (lpMsgBuf[srclen-1] == '\n' || lpMsgBuf[srclen-1] == '\r')) srclen--; unsigned l = fl_utf8fromwc(NULL, 0, lpMsgBuf, srclen); *perr_message = new char[l+51]; - sprintf(*perr_message, "begin_job() failed with error %lu: ", dw); + snprintf(*perr_message, l+51, "begin_job() failed with error %lu: ", dw); fl_utf8fromwc(*perr_message + strlen(*perr_message), l+1, lpMsgBuf, srclen); LocalFree(lpMsgBuf); } diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx index 3aaa4401c..237243975 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx @@ -742,7 +742,7 @@ int Fl_WinAPI_System_Driver::file_browser_load_filesystem(Fl_File_Browser *brows drives = GetLogicalDrives(); for (int i = 'A'; i <= 'Z'; i ++, drives >>= 1) { if (drives & 1) { - sprintf(filename, "%c:/", i); + snprintf(filename, lname, "%c:/", i); if (i < 'C') // see also: GetDriveType and GetVolumeInformation in Windows browser->add(filename, icon); else @@ -794,7 +794,7 @@ void Fl_WinAPI_System_Driver::newUUID(char *uuidBuffer) (rpc_res == RPC_S_UUID_NO_ADDRESS) // probably only locally unique ) { got_uuid = -1; - sprintf(uuidBuffer, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", + snprintf(uuidBuffer, 36+1, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", pu->Data1, pu->Data2, pu->Data3, pu->Data4[0], pu->Data4[1], pu->Data4[2], pu->Data4[3], pu->Data4[4], pu->Data4[5], pu->Data4[6], pu->Data4[7]); @@ -833,7 +833,7 @@ void Fl_WinAPI_System_Driver::newUUID(char *uuidBuffer) for (int ii = 0; ii < 4; ii++) { b[12 + ii] = (unsigned char)name[ii]; } - sprintf(uuidBuffer, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", + snprintf(uuidBuffer, 36+1, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]); } diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx index da2d2b303..a4b8672ce 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx @@ -457,7 +457,7 @@ static const char *find_best_font(const char *fname, int size) { // whoa! A scalable font! Use unless exact match found: int l = c-thisname; memcpy(namebuffer,thisname,l); - l += sprintf(namebuffer+l,"%d",size); + l += snprintf(namebuffer+l, 1024-l,"%d",size); while (*c == '0') c++; strcpy(namebuffer+l,c); name = namebuffer; diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx index 3a4817b7f..d2fb52d40 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx @@ -1352,7 +1352,7 @@ Fl_Font Fl_Xlib_Graphics_Driver::set_fonts(const char* pattern_name) // build the font's FLTK name l += strlen(p) + 2; char *q = new char[l]; - sprintf(q, "%s %s", fam_name, p); + snprintf(q, l, "%s %s", fam_name, p); Fl::set_font((Fl_Font)(count++ + FL_FREE_FONT), q); } /*g_*/free(faces); // glib source code shows that g_free is equivalent to free |
