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 /test | |
| parent | 53d9614adbb728fc4db983c9bb817c6eea870994 (diff) | |
Replace all calls to sprintf() by calls to snprintf().
Diffstat (limited to 'test')
| -rw-r--r-- | test/ask.cxx | 2 | ||||
| -rw-r--r-- | test/blocks.cxx | 10 | ||||
| -rw-r--r-- | test/boxtype.cxx | 2 | ||||
| -rw-r--r-- | test/checkers.cxx | 2 | ||||
| -rw-r--r-- | test/clipboard.cxx | 8 | ||||
| -rw-r--r-- | test/colbrowser.cxx | 2 | ||||
| -rw-r--r-- | test/demo.cxx | 8 | ||||
| -rw-r--r-- | test/file_chooser.cxx | 10 | ||||
| -rw-r--r-- | test/fonts.cxx | 6 | ||||
| -rw-r--r-- | test/fractals.cxx | 2 | ||||
| -rw-r--r-- | test/fullscreen.cxx | 8 | ||||
| -rw-r--r-- | test/glpuzzle.cxx | 4 | ||||
| -rw-r--r-- | test/keyboard.cxx | 12 | ||||
| -rw-r--r-- | test/list_visuals.cxx | 2 | ||||
| -rw-r--r-- | test/mandelbrot.cxx | 8 | ||||
| -rw-r--r-- | test/menubar.cxx | 2 | ||||
| -rw-r--r-- | test/pack.cxx | 2 | ||||
| -rw-r--r-- | test/scroll.cxx | 2 | ||||
| -rw-r--r-- | test/sudoku.cxx | 16 | ||||
| -rw-r--r-- | test/symbols.cxx | 18 | ||||
| -rw-r--r-- | test/table.cxx | 4 | ||||
| -rw-r--r-- | test/threads.cxx | 2 | ||||
| -rw-r--r-- | test/tree.fl | 4 | ||||
| -rw-r--r-- | test/unittest_scrollbarsize.cxx | 2 | ||||
| -rw-r--r-- | test/utf8.cxx | 10 |
25 files changed, 74 insertions, 74 deletions
diff --git a/test/ask.cxx b/test/ask.cxx index 8c708cad1..0c2365149 100644 --- a/test/ask.cxx +++ b/test/ask.cxx @@ -106,7 +106,7 @@ void timer_cb(void *) { // test message title assignment with a local buffer { // local scope for buf char buf[40]; // test: use local variable - sprintf(buf, "Message #%d", n); // fill message title + snprintf(buf, 40, "Message #%d", n); // fill message title fl_message_title(buf); // set message title strcpy(buf, "** void **"); // overwrite buffer to be sure } // buf goes out of scope here diff --git a/test/blocks.cxx b/test/blocks.cxx index f6fbbb48c..d50944f79 100644 --- a/test/blocks.cxx +++ b/test/blocks.cxx @@ -720,21 +720,21 @@ void BlockWindow::draw() { // Draw the scores and level... char s[255]; - sprintf(s, " Score: %d", score_); + snprintf(s, sizeof(s), " Score: %d", score_); fl_color(FL_WHITE); fl_font(FL_HELVETICA, 14); fl_draw(s, 40, 0, w() - 40, 20, FL_ALIGN_LEFT); - sprintf(s, "High Score: %d ", high_score_); + snprintf(s, sizeof(s), "High Score: %d ", high_score_); fl_draw(s, 0, 0, w(), 20, FL_ALIGN_RIGHT); if (level_ > 1 || title_y_ <= 0) { - sprintf(s, "Level: %d ", level_); + snprintf(s, sizeof(s), "Level: %d ", level_); fl_draw(s, 0, 0, w(), 20, FL_ALIGN_CENTER); } if (show_fps_) { - sprintf(s, "FPS: %d ", frames_per_second_); + snprintf(s, sizeof(s), "FPS: %d ", frames_per_second_); fl_draw(s, 0, h() - 20, w(), 20, FL_ALIGN_LEFT); } @@ -898,7 +898,7 @@ void BlockWindow::up_level() { opened_columns_ = 0; if (num_colors_ < 7) num_colors_ ++; level_ ++; - sprintf(title_, "Level: %d", level_); + snprintf(title_, sizeof(title_), "Level: %d", level_); title_y_ = h(); } diff --git a/test/boxtype.cxx b/test/boxtype.cxx index dc23318cf..17733947a 100644 --- a/test/boxtype.cxx +++ b/test/boxtype.cxx @@ -113,7 +113,7 @@ int main(int argc, char ** argv) { // set window title to show active scheme Fl::scheme(Fl::scheme()); // init scheme char title[100]; - sprintf(title,"FLTK boxtypes: scheme = '%s'",Fl::scheme()?Fl::scheme():"none"); + snprintf(title, 100,"FLTK boxtypes: scheme = '%s'",Fl::scheme()?Fl::scheme():"none"); window->label(title); // create special container group for box size debugging diff --git a/test/checkers.cxx b/test/checkers.cxx index 8944bb35a..e0904ba02 100644 --- a/test/checkers.cxx +++ b/test/checkers.cxx @@ -963,7 +963,7 @@ void Board::draw() { int y1 = squarey(n->from)+BOXSIZE/2-5; int x2 = squarex(n->to)+BOXSIZE/2-5; int y2 = squarey(n->to)+BOXSIZE/2-5; - char buf[20]; sprintf(buf,"%d",num); + char buf[20]; snprintf(buf, 20,"%d",num); fl_draw(buf, x1+int((x2-x1)*.85)-3, y1+int((y2-y1)*.85)+5); num++; } diff --git a/test/clipboard.cxx b/test/clipboard.cxx index ae517b988..3688d01cb 100644 --- a/test/clipboard.cxx +++ b/test/clipboard.cxx @@ -95,7 +95,7 @@ public: if (!cl_img) return 1; char title[300]; - sprintf(title, "%dx%d", cl_img->w(), cl_img->h()); // display the image original size + snprintf(title, 300, "%dx%d", cl_img->w(), cl_img->h()); // display the image original size // optional: display extra technical info about clipboard content @@ -105,20 +105,20 @@ public: char *p = title + strlen(title); int format = EnumClipboardFormats(0); if (format && format < CF_MAX) { - sprintf(p, " %d", format); + snprintf(p, sizeof(title) - strlen(title), " %d", format); p += strlen(p); } while (format) { format = EnumClipboardFormats(format); if (format && format < CF_MAX) { - sprintf(p, " %d", format); + snprintf(p, sizeof(title) - strlen(title), " %d", format); p += strlen(p); } } HANDLE h; if ((h = GetClipboardData(CF_DIB))) { LPBITMAPINFO lpBI = (LPBITMAPINFO)GlobalLock(h); - sprintf(p, " biBitCount=%d biCompression=%d biClrUsed=%d", + snprintf(p, sizeof(title) - strlen(title), " biBitCount=%d biCompression=%d biClrUsed=%d", lpBI->bmiHeader.biBitCount, (int)lpBI->bmiHeader.biCompression, (int)lpBI->bmiHeader.biClrUsed); diff --git a/test/colbrowser.cxx b/test/colbrowser.cxx index eedb5499f..cbd760eb7 100644 --- a/test/colbrowser.cxx +++ b/test/colbrowser.cxx @@ -157,7 +157,7 @@ static int load_browser(const char *fname) lr = r; lg = g; lb = b; - sprintf(buf, "(%3d %3d %3d) %s", r, g, b, name); + snprintf(buf, sizeof(buf), "(%3d %3d %3d) %s", r, g, b, name); colbr->add(buf); } } diff --git a/test/demo.cxx b/test/demo.cxx index 0dbe41ed4..e23907ba6 100644 --- a/test/demo.cxx +++ b/test/demo.cxx @@ -407,17 +407,17 @@ void dobut(Fl_Widget *, long arg) { if (params[0]) { // we assume that we have only one argument which is a filename in 'data_path' - sprintf(command, "open '%s/%s%s' --args '%s/%s'", path, cmdbuf, suffix, data_path, params); + snprintf(command, sizeof(command), "open '%s/%s%s' --args '%s/%s'", path, cmdbuf, suffix, data_path, params); } else { - sprintf(command, "open '%s/%s%s'", path, cmdbuf, suffix); + snprintf(command, sizeof(command), "open '%s/%s%s'", path, cmdbuf, suffix); } #else // other platforms if (params[0]) - sprintf(command, "%s/%s%s %s", path, cmdbuf, suffix, params); + snprintf(command, sizeof(command), "%s/%s%s %s", path, cmdbuf, suffix, params); else - sprintf(command, "%s/%s%s", path, cmdbuf, suffix); + snprintf(command, sizeof(command), "%s/%s%s", path, cmdbuf, suffix); #endif diff --git a/test/file_chooser.cxx b/test/file_chooser.cxx index b705f052e..a79ef2023 100644 --- a/test/file_chooser.cxx +++ b/test/file_chooser.cxx @@ -295,9 +295,9 @@ pdf_check(const char *name, // I - Name of file return 0; home = fl_getenv("HOME"); - sprintf(preview, "%s/.preview.ppm", home ? home : ""); + snprintf(preview, FL_PATH_MAX, "%s/.preview.ppm", home ? home : ""); - sprintf(command, + snprintf(command, sizeof(command), "gs -r100 -dFIXED -sDEVICE=ppmraw -dQUIET -dNOPAUSE -dBATCH " "-sstdout=\"%%stderr\" -sOUTPUTFILE=\'%s\' " "-dFirstPage=1 -dLastPage=1 \'%s\' 2>/dev/null", preview, name); @@ -331,11 +331,11 @@ ps_check(const char *name, // I - Name of file return 0; home = fl_getenv("HOME"); - sprintf(preview, "%s/.preview.ppm", home ? home : ""); + snprintf(preview, FL_PATH_MAX, "%s/.preview.ppm", home ? home : ""); if (memcmp(header, "%!PS", 4) == 0) { // PS file has DSC comments; extract the first page... - sprintf(outname, "%s/.preview.ps", home ? home : ""); + snprintf(outname, FL_PATH_MAX, "%s/.preview.ps", home ? home : ""); if (strcmp(name, outname) != 0) { in = fl_fopen(name, "rb"); @@ -360,7 +360,7 @@ ps_check(const char *name, // I - Name of file outname[sizeof(outname) - 1] = '\0'; } - sprintf(command, + snprintf(command, sizeof(command), "gs -r100 -dFIXED -sDEVICE=ppmraw -dQUIET -dNOPAUSE -dBATCH " "-sstdout=\"%%stderr\" -sOUTPUTFILE=\'%s\' \'%s\' 2>/dev/null", preview, outname); diff --git a/test/fonts.cxx b/test/fonts.cxx index 16fec4460..694b1d7bf 100644 --- a/test/fonts.cxx +++ b/test/fonts.cxx @@ -68,8 +68,8 @@ void font_cb(Fl_Widget *, long) { int j = 1; for (int i = 1; i<64 || i<s[n-1]; i++) { char buf[20]; - if (j < n && i==s[j]) {sprintf(buf,"@b%d",i); j++;} - else sprintf(buf,"%d",i); + if (j < n && i==s[j]) {snprintf(buf, 20,"@b%d",i); j++;} + else snprintf(buf, 20,"%d",i); sizeobj->add(buf); } sizeobj->value(pickedsize); @@ -79,7 +79,7 @@ void font_cb(Fl_Widget *, long) { for (int i = 0; i < n; i++) { if (s[i]<=pickedsize) w = i; char buf[20]; - sprintf(buf,"@b%d",s[i]); + snprintf(buf, 20,"@b%d",s[i]); sizeobj->add(buf); } sizeobj->value(w+1); diff --git a/test/fractals.cxx b/test/fractals.cxx index bea5bf3d5..b680d3d0d 100644 --- a/test/fractals.cxx +++ b/test/fractals.cxx @@ -637,7 +637,7 @@ void display(void) glLoadIdentity(); gluOrtho2D(0.0, winwidth, 0.0, winheight); - sprintf(buf, "FPS=%d", fps); + snprintf(buf, sizeof(buf), "FPS=%d", fps); glColor3f(1.0f, 1.0f, 1.0f); gl_font(FL_HELVETICA, 12); gl_draw(buf, 10, 10); diff --git a/test/fullscreen.cxx b/test/fullscreen.cxx index 8bde3cf5f..96f2c7cb5 100644 --- a/test/fullscreen.cxx +++ b/test/fullscreen.cxx @@ -226,20 +226,20 @@ void update_screeninfo(Fl_Widget *b, void *p) { char line[128]; browser->clear(); - sprintf(line, "Main screen work area: %dx%d@%d,%d", Fl::w(), Fl::h(), Fl::x(), Fl::y()); + snprintf(line, sizeof(line), "Main screen work area: %dx%d@%d,%d", Fl::w(), Fl::h(), Fl::x(), Fl::y()); browser->add(line); Fl::screen_work_area(x, y, w, h); - sprintf(line, "Mouse screen work area: %dx%d@%d,%d", w, h, x, y); + snprintf(line, sizeof(line), "Mouse screen work area: %dx%d@%d,%d", w, h, x, y); browser->add(line); for (int n = 0; n < Fl::screen_count(); n++) { int x, y, w, h; float dpih, dpiv; Fl::screen_xywh(x, y, w, h, n); Fl::screen_dpi(dpih, dpiv, n); - sprintf(line, "Screen %d: %dx%d@%d,%d DPI:%.1fx%.1f scale:%.2f", n, w, h, x, y, dpih, dpiv, Fl::screen_scale(n)); + snprintf(line, sizeof(line), "Screen %d: %dx%d@%d,%d DPI:%.1fx%.1f scale:%.2f", n, w, h, x, y, dpih, dpiv, Fl::screen_scale(n)); browser->add(line); Fl::screen_work_area(x, y, w, h, n); - sprintf(line, "Work area %d: %dx%d@%d,%d", n, w, h, x, y); + snprintf(line, sizeof(line), "Work area %d: %dx%d@%d,%d", n, w, h, x, y); browser->add(line); } } diff --git a/test/glpuzzle.cxx b/test/glpuzzle.cxx index d966ced01..1c1f8b4e4 100644 --- a/test/glpuzzle.cxx +++ b/test/glpuzzle.cxx @@ -491,7 +491,7 @@ solidifyChain(struct puzzle *puzzle) puzzle->backptr->solnptr = puzzle; puzzle = puzzle->backptr; } - sprintf(buf, "%d moves to complete!", i); + snprintf(buf, 256, "%d moves to complete!", i); glutSetWindowTitle(buf); } @@ -763,7 +763,7 @@ solvePuzzle(void) } if (puzzles == NULL) { freeSolutions(); - sprintf(buf, "I can't solve it! (%d positions examined)", i); + snprintf(buf, 256, "I can't solve it! (%d positions examined)", i); glutSetWindowTitle(buf); return 1; } diff --git a/test/keyboard.cxx b/test/keyboard.cxx index feb896c3f..a3603cabf 100644 --- a/test/keyboard.cxx +++ b/test/keyboard.cxx @@ -119,20 +119,20 @@ int main(int argc, char** argv) { if (!k) keyname = "0"; else if (k < 128) { // ASCII - sprintf(buffer, "'%c'", k); + snprintf(buffer, sizeof(buffer), "'%c'", k); } else if (k >= 0xa0 && k <= 0xff) { // ISO-8859-1 (international keyboards) char key[8]; int kl = fl_utf8encode((unsigned)k, key); key[kl] = '\0'; - sprintf(buffer, "'%s'", key); + snprintf(buffer, sizeof(buffer), "'%s'", key); } else if (k > FL_F && k <= FL_F_Last) { - sprintf(buffer, "FL_F+%d", k - FL_F); + snprintf(buffer, sizeof(buffer), "FL_F+%d", k - FL_F); } else if (k >= FL_KP && k <= FL_KP_Last) { - sprintf(buffer, "FL_KP+'%c'", k-FL_KP); + snprintf(buffer, sizeof(buffer), "FL_KP+'%c'", k-FL_KP); } else if (k >= FL_Button && k <= FL_Button+7) { - sprintf(buffer, "FL_Button+%d", k-FL_Button); + snprintf(buffer, sizeof(buffer), "FL_Button+%d", k-FL_Button); } else { - sprintf(buffer, "0x%04x", k); + snprintf(buffer, sizeof(buffer), "0x%04x", k); for (int i = 0; i < int(sizeof(table)/sizeof(*table)); i++) if (table[i].n == k) {keyname = table[i].text; break;} } diff --git a/test/list_visuals.cxx b/test/list_visuals.cxx index 18b98045f..1d57f5e93 100644 --- a/test/list_visuals.cxx +++ b/test/list_visuals.cxx @@ -92,7 +92,7 @@ static void print_mask(XVisualInfo* p) { else new_what = '?'; if (new_what != what) { if (what && (what != '?' || print_anything)) { - q += sprintf(q,"%d%c", n, what); + q += snprintf(q, sizeof(buf) - (q-buf), "%d%c", n, what); print_anything = 1; } what = new_what; diff --git a/test/mandelbrot.cxx b/test/mandelbrot.cxx index d6cbe338a..f233ffb63 100644 --- a/test/mandelbrot.cxx +++ b/test/mandelbrot.cxx @@ -72,9 +72,9 @@ int main(int argc, char **argv) { void Drawing_Window::update_label() { char buffer[128]; - sprintf(buffer, "%+.10f", d->X); x_input->value(buffer); - sprintf(buffer, "%+.10f", d->Y); y_input->value(buffer); - sprintf(buffer, "%.2g", d->scale); w_input->value(buffer); + snprintf(buffer, 128, "%+.10f", d->X); x_input->value(buffer); + snprintf(buffer, 128, "%+.10f", d->Y); y_input->value(buffer); + snprintf(buffer, 128, "%.2g", d->scale); w_input->value(buffer); } void Drawing_Area::draw() { @@ -187,7 +187,7 @@ int Drawing_Area::handle(int event) { jbrot.d->jX = X + (ix-x()-W/2)*scale/W; jbrot.d->jY = Y + (H/2-iy+y())*scale/W; static char s[128]; - sprintf(s, "Julia %.7f %.7f",jbrot.d->jX,jbrot.d->jY); + snprintf(s, 128, "Julia %.7f %.7f",jbrot.d->jX,jbrot.d->jY); jbrot.window->label(s); jbrot.window->show(); jbrot.d->new_display(); diff --git a/test/menubar.cxx b/test/menubar.cxx index d36c3e91e..1f7750007 100644 --- a/test/menubar.cxx +++ b/test/menubar.cxx @@ -225,7 +225,7 @@ int main(int argc, char **argv) { //Fl::set_color(Fl_Color(15),0,0,128); for (int i=0; i<99; i++) { char buf[100]; - sprintf(buf,"item %d",i); + snprintf(buf, 100,"item %d",i); hugemenu[i].text = fl_strdup(buf); } Fl_Double_Window window(WIDTH,400+TERMINAL_HEIGHT); diff --git a/test/pack.cxx b/test/pack.cxx index 64398ddab..62ff92323 100644 --- a/test/pack.cxx +++ b/test/pack.cxx @@ -104,7 +104,7 @@ int main(int argc, char **argv) { int xx = 35; for (int i = 0; i < nbuttons; i++) { char ltxt[8]; - sprintf(ltxt, "b%d", i + 1); + snprintf(ltxt, 8, "b%d", i + 1); Fl_Button *b = new Fl_Button(xx, xx, 25, 25); b->copy_label(ltxt); xx += 10; diff --git a/test/scroll.cxx b/test/scroll.cxx index 2ca5ac142..5403613ea 100644 --- a/test/scroll.cxx +++ b/test/scroll.cxx @@ -95,7 +95,7 @@ int main(int argc, char** argv) { int n = 0; for (int y=0; y<16; y++) for (int x=0; x<5; x++) { - char buf[20]; sprintf(buf,"%d",n++); + char buf[20]; snprintf(buf, 20,"%d",n++); Fl_Button* b = new Fl_Button(x*75,y*25+(y>=8?5*75:0),75,25); b->copy_label(buf); b->color(n); diff --git a/test/sudoku.cxx b/test/sudoku.cxx index 9884c117d..d7b856bc7 100644 --- a/test/sudoku.cxx +++ b/test/sudoku.cxx @@ -1006,7 +1006,7 @@ Sudoku::load_game() { SudokuCell *cell = grid_cells_[j][k]; - sprintf(name, "value%d.%d", j, k); + snprintf(name, sizeof(name), "value%d.%d", j, k); if (!prefs_.get(name, val, 0)) { j = 9; grid_values_[0][0] = 0; @@ -1015,11 +1015,11 @@ Sudoku::load_game() { grid_values_[j][k] = val; - sprintf(name, "state%d.%d", j, k); + snprintf(name, sizeof(name), "state%d.%d", j, k); prefs_.get(name, val, 0); cell->value(val); - sprintf(name, "readonly%d.%d", j, k); + snprintf(name, sizeof(name), "readonly%d.%d", j, k); prefs_.get(name, val, 0); cell->readonly(val != 0); @@ -1030,7 +1030,7 @@ Sudoku::load_game() { } for (int m = 0; m < 8; m ++) { - sprintf(name, "test%d%d.%d", m, j, k); + snprintf(name, sizeof(name), "test%d%d.%d", m, j, k); prefs_.get(name, val, 0); cell->test_value(val, m); } @@ -1261,17 +1261,17 @@ Sudoku::save_game() { char name[255]; SudokuCell *cell = grid_cells_[j][k]; - sprintf(name, "value%d.%d", j, k); + snprintf(name, sizeof(name), "value%d.%d", j, k); prefs_.set(name, grid_values_[j][k]); - sprintf(name, "state%d.%d", j, k); + snprintf(name, sizeof(name), "state%d.%d", j, k); prefs_.set(name, cell->value()); - sprintf(name, "readonly%d.%d", j, k); + snprintf(name, sizeof(name), "readonly%d.%d", j, k); prefs_.set(name, cell->readonly()); for (int m = 0; m < 8; m ++) { - sprintf(name, "test%d%d.%d", m, j, k); + snprintf(name, sizeof(name), "test%d%d.%d", m, j, k); prefs_.set(name, cell->test_value(m)); } } diff --git a/test/symbols.cxx b/test/symbols.cxx index 43f5217d8..d97dfa834 100644 --- a/test/symbols.cxx +++ b/test/symbols.cxx @@ -44,15 +44,15 @@ void slider_cb(Fl_Widget *, void *) { if ( l && *l == '@' ) { // all children with '@' l ++; if ( wc->box() == FL_NO_BOX ) { // ascii legend? - if (val&&sze) sprintf(buf, "@@%+d%d%s", sze, val, l); - else if (val) sprintf(buf, "@@%d%s", val, l); - else if (sze) sprintf(buf, "@@%+d%s", sze, l); - else sprintf(buf, "@@%s", l); + if (val&&sze) snprintf(buf, sizeof(buf), "@@%+d%d%s", sze, val, l); + else if (val) snprintf(buf, sizeof(buf), "@@%d%s", val, l); + else if (sze) snprintf(buf, sizeof(buf), "@@%+d%s", sze, l); + else snprintf(buf, sizeof(buf), "@@%s", l); } else { // box with symbol - if (val&&sze) sprintf(buf, "@%+d%d%s", sze, val, l); - else if (val) sprintf(buf, "@%d%s", val, l); - else if (sze) sprintf(buf, "@%+d%s", sze, l); - else sprintf(buf, "@%s", l); + if (val&&sze) snprintf(buf, sizeof(buf), "@%+d%d%s", sze, val, l); + else if (val) snprintf(buf, sizeof(buf), "@%d%s", val, l); + else if (sze) snprintf(buf, sizeof(buf), "@%+d%s", sze, l); + else snprintf(buf, sizeof(buf), "@%s", l); } wc->copy_label(buf); } @@ -67,7 +67,7 @@ void bt(const char *name) { N++; x = x*W+10; y = y*H+10; - sprintf(buf, "@%s", name); + snprintf(buf, sizeof(buf), "@%s", name); Fl_Box *a = new Fl_Box(x,y,W-20,H-20); a->box(FL_NO_BOX); a->copy_label(buf); diff --git a/test/table.cxx b/test/table.cxx index 1a540ea4f..dbca2e89f 100644 --- a/test/table.cxx +++ b/test/table.cxx @@ -54,7 +54,7 @@ void DemoTable::draw_cell(TableContext context, int R, int C, int X, int Y, int W, int H) { static char s[40]; - sprintf(s, "%d/%d", R, C); // text for each cell + snprintf(s, 40, "%d/%d", R, C); // text for each cell switch ( context ) { @@ -271,7 +271,7 @@ void setcellbgcolor_cb(Fl_Widget *w, void *data) char *itoa(int val) { static char s[80]; - sprintf(s, "%d", val); + snprintf(s, 80, "%d", val); return(s); } diff --git a/test/threads.cxx b/test/threads.cxx index 68370d246..f7349a668 100644 --- a/test/threads.cxx +++ b/test/threads.cxx @@ -73,7 +73,7 @@ extern "C" void* prime_func(void* p) for (pp=3; pp<=hn; pp+=2) if ( n%pp == 0 ) break; if (pp >= hn) { char s[128]; - sprintf(s, "%d", n); + snprintf(s, 128, "%d", n); // Obtain a lock before we access the browser widget... Fl::lock(); diff --git a/test/tree.fl b/test/tree.fl index d44d4c08b..ea068a5c8 100644 --- a/test/tree.fl +++ b/test/tree.fl @@ -270,7 +270,7 @@ tree->add("Long Line/Longer Line/The quick brown fox jumped over the lazy dog. - // Add 500 items in numerical order for ( int t=0; t<500; t++ ) { static char s[80]; - sprintf(s, "500 Items/item %04d", t+1); + snprintf(s, 80, "500 Items/item %04d", t+1); tree->add(s); } tree->close("500 Items"); // close the 500 items by default @@ -986,7 +986,7 @@ while (item) { if ( parent == 0 ) parent = tree->root(); char s[80]; for ( int i=0; i<20000; i++ ) { - sprintf(s, "Item \#%d", item_id+i); + snprintf(s, 80, "Item \#%d", item_id+i); tree->add(parent, s); } item_id += 20000; diff --git a/test/unittest_scrollbarsize.cxx b/test/unittest_scrollbarsize.cxx index 9ecdf73fe..8f2b30311 100644 --- a/test/unittest_scrollbarsize.cxx +++ b/test/unittest_scrollbarsize.cxx @@ -39,7 +39,7 @@ class MyTable : public Fl_Table { fl_font(FL_HELVETICA, 8); // set font for drawing operations return; case CONTEXT_CELL: // Draw data in cells - sprintf(s, "%c", 'A'+ROW+COL); + snprintf(s, 10, "%c", 'A'+ROW+COL); fl_push_clip(X,Y,W,H); // Draw cell bg fl_color(FL_WHITE); fl_rectf(X,Y,W,H); diff --git a/test/utf8.cxx b/test/utf8.cxx index 130f411fa..ce5cd9378 100644 --- a/test/utf8.cxx +++ b/test/utf8.cxx @@ -174,11 +174,11 @@ static void font_cb(Fl_Widget *, long) char buf[16]; if (j < size_count && i == size_array[j]) { - sprintf(buf, "@b%d", i); + snprintf(buf, 16, "@b%d", i); j++; } else - sprintf(buf, "%d", i); + snprintf(buf, 16, "%d", i); sizeobj->add(buf); } sizeobj->value(pickedsize); @@ -193,7 +193,7 @@ static void font_cb(Fl_Widget *, long) if (size_array[i] <= pickedsize) w = i; char buf[16]; - sprintf(buf, "@b%d", size_array[i]); + snprintf(buf, 16, "@b%d", size_array[i]); sizeobj->add(buf); } sizeobj->value(w + 1); @@ -304,7 +304,7 @@ static void own_face_cb(Fl_Widget *, void *) // Show font in its own face // this is neat, but really slow on some systems: // uses each font to display its own name - sprintf (buffer, "@F%d@.%s", font_idx, name); + snprintf (buffer, sizeof(buffer), "@F%d@.%s", font_idx, name); } fontobj->add(buffer); } @@ -616,7 +616,7 @@ int main(int argc, char** argv) i++; } buf[o] = '\0'; - sprintf(bu, "0x%06lX", y * 16); + snprintf(bu, sizeof(bu), "0x%06lX", y * 16); Fl_Input *b = new Fl_Input(200,(y-off)*25,80,25); b->textfont(FL_COURIER); b->value(fl_strdup(bu)); |
