use snprintf() in Get_color_behind_window() and Status_print_palette_color()

This commit is contained in:
Thomas Bernard 2018-11-06 16:27:23 +01:00
parent 67dc001e7c
commit afe65bfb92
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -572,11 +572,12 @@ void Status_print_palette_color(byte color)
char str[25]; char str[25];
int i; int i;
strcpy(str,Buttons_Pool[BUTTON_CHOOSE_COL].Tooltip); i = snprintf(str, sizeof(str), "%s%d (%d,%d,%d)",
sprintf(str+strlen(str),"%d (%d,%d,%d)",color,Main.palette[color].R,Main.palette[color].G,Main.palette[color].B); Buttons_Pool[BUTTON_CHOOSE_COL].Tooltip, color,
Main.palette[color].R,Main.palette[color].G,Main.palette[color].B);
// Pad spaces // Pad spaces
for (i=strlen(str); i<24; i++) while(i<24)
str[i]=' '; str[i++]=' ';
str[24]='\0'; str[24]='\0';
Print_in_menu(str,0); Print_in_menu(str,0);
@ -2576,18 +2577,13 @@ void Get_color_behind_window(byte * color, byte * click)
c=a; // Mise à jour de la couleur pointée c=a; // Mise à jour de la couleur pointée
if (Menu_is_visible_before_window) if (Menu_is_visible_before_window)
{ {
sprintf(str,"%d",a); d = snprintf(str, sizeof(str), "%d", a); // position of the space to color
d=strlen(str); index = snprintf(str+d, sizeof(str)-d, " (%d,%d,%d)",
strcat(str," ("); Main.palette[a].R, Main.palette[a].G, Main.palette[a].B);
sprintf(str+strlen(str),"%d",Main.palette[a].R); index += d;
strcat(str,",");
sprintf(str+strlen(str),"%d",Main.palette[a].G);
strcat(str,",");
sprintf(str+strlen(str),"%d",Main.palette[a].B);
strcat(str,")");
a=24-d; a=24-d;
for (index=strlen(str); index<a; index++) while (index<a)
str[index]=' '; str[index++]=' ';
str[a]=0; str[a]=0;
Print_in_menu(str,strlen(Buttons_Pool[BUTTON_CHOOSE_COL].Tooltip)); Print_in_menu(str,strlen(Buttons_Pool[BUTTON_CHOOSE_COL].Tooltip));