From 848ec95e92e44007cc43cb8364f0a34c24c906a1 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 24 Jul 2019 03:04:08 +0200 Subject: [PATCH] fix warnings caused by sprintf() note : %hhu is C99, old mingw32 compiler complains about it --- src/buttons.c | 8 +++----- src/buttons_effects.c | 14 +++++++++----- src/graph.c | 2 +- src/graph.h | 2 +- src/loadsave.c | 10 ++-------- src/misc.h | 2 +- src/palette.c | 26 ++++++++------------------ src/windows.c | 8 ++++---- 8 files changed, 29 insertions(+), 43 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index d978eab5..a6a92256 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -1855,9 +1855,7 @@ void Display_modes_list(short list_start, short cursor_position) else text_color=MC_White; } - Num2str(Video_mode[current_mode].Width,str,4); - str[4]=' '; - Num2str(Video_mode[current_mode].Height,str+5,4); + snprintf(str, sizeof(str), "%4hu %4hu", Video_mode[current_mode].Width, Video_mode[current_mode].Height); if(Video_mode[current_mode].Fullscreen == 0) memcpy(str+9," Window ",20); @@ -1915,7 +1913,7 @@ void Button_Resolution(int btn) short list_start; short cursor_position; short temp; - char str[5]; + char str[8]; T_Special_button * input_width_button, * input_button_height; T_Dropdown_button * pixel_button; static const char *pixel_ratio_labels[PIXEL_MAX] ={ @@ -4197,7 +4195,7 @@ void Button_Airbrush(int btn) void Refresh_airbrush_settings(byte selected_color, byte update_slider) { - char str[3]; + char str[4]; if (update_slider) { diff --git a/src/buttons_effects.c b/src/buttons_effects.c index f1549f75..8c0a6bcf 100644 --- a/src/buttons_effects.c +++ b/src/buttons_effects.c @@ -48,6 +48,10 @@ #include "palette.h" #include "layers.h" +#ifndef MIN +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif + //---------- Menu dans lequel on tagge des couleurs (genre Stencil) ---------- void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section, word close_shortcut) { @@ -1052,12 +1056,12 @@ void Button_Grid_menu(void) Print_in_window(11,26, "X:",MC_Dark,MC_Light); input_x_button = Window_set_input_button(29,24,3); // 3 - Num2str(chosen_X,str,3); + Num2str(MIN(chosen_X, 999), str, 3); Window_input_content(input_x_button,str); Print_in_window(11,47, "Y:",MC_Dark,MC_Light); input_y_button = Window_set_input_button(29,45,3); // 4 - Num2str(chosen_Y,str,3); + Num2str(MIN(chosen_Y, 999), str, 3); Window_input_content(input_y_button,str); Print_in_window(77,26,"dX:",MC_Dark,MC_Light); @@ -1086,7 +1090,7 @@ void Button_Grid_menu(void) switch (clicked_button) { case 3 : - Num2str(chosen_X,str,3); + Num2str(MIN(chosen_X, 999), str, 3); Readline(31,26,str,3,INPUT_TYPE_INTEGER); chosen_X=atoi(str); // On corrige les dimensions @@ -1108,7 +1112,7 @@ void Button_Grid_menu(void) Display_cursor(); break; case 4 : - Num2str(chosen_Y,str,3); + Num2str(MIN(chosen_Y, 999), str, 3); Readline(31,47,str,3,INPUT_TYPE_INTEGER); chosen_Y=atoi(str); // On corrige les dimensions @@ -1235,7 +1239,7 @@ void Button_Smooth_menu(void) word x,y,i,j; byte chosen_matrix[3][3]; T_Special_button * matrix_input[3][3]; - char str[3]; + char str[4]; Open_window(142,109,"Smooth"); diff --git a/src/graph.c b/src/graph.c index b314a528..f9534f1c 100644 --- a/src/graph.c +++ b/src/graph.c @@ -1179,7 +1179,7 @@ void Fill_general(byte fill_color) } // Affichage d'un point pour une preview en xor - void Pixel_figure_preview_xor(short x_pos,short y_pos,byte color) + void Pixel_figure_preview_xor(word x_pos,word y_pos,byte color) { (void)color; // unused diff --git a/src/graph.h b/src/graph.h index 7513ec14..a6c290bf 100644 --- a/src/graph.h +++ b/src/graph.h @@ -60,7 +60,7 @@ void Replace(byte New_color); void Pixel_figure_preview (word x_pos,word y_pos,byte color); void Pixel_figure_preview_auto(word x_pos,word y_pos); -void Pixel_figure_preview_xor(short x_pos,short y_pos,byte color); +void Pixel_figure_preview_xor(word x_pos,word y_pos,byte color); void Pixel_figure_preview_xorback(word x_pos,word y_pos,byte color); void Pixel_figure_in_brush(word x_pos,word y_pos,byte color); diff --git a/src/loadsave.c b/src/loadsave.c index b95bd34a..fb8d782c 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -400,17 +400,11 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size, if (context->Original_width != 0) { if (context->Original_width < 10000 && context->Original_height < 10000) - { - Num2str(context->Original_width,str,4); - Num2str(context->Original_height,str+5,4); - str[4]='x'; - } + snprintf(str, sizeof(str), "%4hux%4hu", context->Original_width, context->Original_height); } else if ((width<10000) && (height<10000)) { - Num2str(width,str,4); - Num2str(height,str+5,4); - str[4]='x'; + snprintf(str, sizeof(str), "%4hux%4hu", width, height); } Print_in_window(101,59,str,MC_Black,MC_Light); snprintf(str, sizeof(str), "%2dbpp", bpp); diff --git a/src/misc.h b/src/misc.h index 68121094..2e40d325 100644 --- a/src/misc.h +++ b/src/misc.h @@ -134,7 +134,7 @@ void Atari_Memory_free(unsigned long *stRam,unsigned long *ttRam); #else unsigned long Memory_free(void); #endif -#define Num2str(a,b,c) sprintf(b,"%*lu",c,(long)(a)) +#define Num2str(a,b,c) snprintf(b,sizeof(b),"%*lu",(int)c,(unsigned long)(a)) #define Dec2str(a,b,c) sprintf(b,"%.*f",c,(double)(a)) diff --git a/src/palette.c b/src/palette.c index 82b4f3fc..b60fbf73 100644 --- a/src/palette.c +++ b/src/palette.c @@ -207,9 +207,7 @@ void Set_blue(byte color, short new_color, T_Palette palette) void Format_component(byte value, char *str) // Formate une chaine de 4 caractères+\0 : "nnn " { - Num2str(value,str,3); - str[3]=' '; - str[4]='\0'; + snprintf(str, 5, "%3u ", (unsigned)value); } void Spread_colors(short start,short end,T_Palette palette) @@ -1013,11 +1011,11 @@ int Window_Histogram(unsigned char block_start, unsigned char block_end, dword* // When changing hovered color, update the info area if (new_hovered_color!=hovered_color) { - char str[12]; + char str[20]; hovered_color=new_hovered_color; Hide_cursor(); - if (hovered_color==-1) + if (hovered_color < 0) { Window_rectangle(6+6*8,17,3*8,7,MC_Light); Update_window_area(6+6*8,17,3*8,7); @@ -1413,9 +1411,7 @@ void Button_Palette(int btn) block_end=temp_color; // Affichage du n° de la couleur sélectionnée - Num2str(block_start,str ,3); - Num2str(block_end ,str+4,3); - str[3]=26; // Flèche vers la droite + snprintf(str, sizeof(str), "%3hu\x1a%3hu", block_start, block_end); // 0x1a : flèche vers la droite Print_in_window(COLOR_X,COLOR_Y,str,MC_Black,MC_Light); // Affichage des jauges @@ -1430,9 +1426,7 @@ void Button_Palette(int btn) block_end=first_color; // Affichage du n° de la couleur sélectionnée - Num2str(block_start,str ,3); - Num2str(block_end ,str+4,3); - str[3]=26; // Flèche vers la droite + snprintf(str, sizeof(str), "%3hu\x1a%3hu", block_start, block_end); // 0x1a : flèche vers la droite Print_in_window(COLOR_X,COLOR_Y,str,MC_Black,MC_Light); // Affichage des jauges @@ -1844,9 +1838,7 @@ void Button_Palette(int btn) if (block_start!=block_end) { // Cas d'un bloc multi-couleur - Num2str(block_start,str ,3); - Num2str(block_end ,str+4,3); - str[3]=26; // Flèche vers la droite + snprintf(str, sizeof(str), "%3hu\x1a%3hu", block_start, block_end); // 0x1a : flèche vers la droite // Affichage dans le block de visu du bloc (dégradé) en cours Display_grad_block_in_window(FGCOLOR_DISPLAY_X,FGCOLOR_DISPLAY_Y,FGCOLOR_DISPLAY_W,FGCOLOR_DISPLAY_H,block_start,block_end); } @@ -1899,9 +1891,7 @@ void Button_Palette(int btn) if (block_start!=block_end) { // Cas d'un bloc multi-couleur - Num2str(block_start,str ,3); - Num2str(block_end ,str+4,3); - str[3]=26; // Flèche vers la droite + snprintf(str, sizeof(str), "%3hu\x1a%3hu", block_start, block_end); // 0x1a : flèche vers la droite // Affichage dans le block de visu du bloc (dégradé) en cours Display_grad_block_in_window(FGCOLOR_DISPLAY_X,FGCOLOR_DISPLAY_Y,FGCOLOR_DISPLAY_W,FGCOLOR_DISPLAY_H,block_start,block_end); } @@ -2908,7 +2898,7 @@ void Button_Secondary_palette(int btn) T_Scroller_button * lines_slider; T_Scroller_button * rgb_scale_slider; T_Scroller_button * gamma_slider; - char str[4]; + char str[8]; byte palette_vertical = Config.Palette_vertical; byte palette_cols, palette_lines; word rgb_scale; diff --git a/src/windows.c b/src/windows.c index 89a06e69..82f8ffda 100644 --- a/src/windows.c +++ b/src/windows.c @@ -608,13 +608,13 @@ void Display_layerbar(void) } if (Menu_bars[MENUBAR_ANIMATION].Visible) { - char str[9]; + char str[24]; // Rest of horizontal line Draw_bar_remainder(MENUBAR_ANIMATION, Menu_bars[MENUBAR_ANIMATION].Skin_width); // Frame# background rectangle // Block((Menu_bars[MENUBAR_ANIMATION].Skin_width)*Menu_factor_X,(0+Menu_bars[MENUBAR_ANIMATION].Top)*Menu_factor_Y+Menu_Y,8*8*Menu_factor_X,8*Menu_factor_Y,MC_Light); // Frame #/# - snprintf(str, 8, "%3d/%3d", Main.current_layer+1, Main.backups->Pages->Nb_layers); + snprintf(str, sizeof(str), "%3d/%3d", Main.current_layer+1, Main.backups->Pages->Nb_layers); Print_general((59)*Menu_factor_X,(Menu_bars[MENUBAR_ANIMATION].Top+3)*Menu_factor_Y+Menu_Y,str,MC_Black,MC_Light); Update_rect( (59)*Menu_factor_X, @@ -1077,9 +1077,9 @@ void Print_coordinates(void) } } - Num2str((dword)Paintbrush_X,temp,4); + Num2str(Paintbrush_X,temp,4); Print_in_menu(temp,2); - Num2str((dword)Paintbrush_Y,temp,4); + Num2str(Paintbrush_Y,temp,4); Print_in_menu(temp,11); } }