* menu.c (menu_scan_hotkey): Use g_strlcpy() to avoid undefined

behavior when using strcpy() on overlapping strings.
* profile.c (GetSetProfile): Likewise.
* widget.c (button_scan_hotkey): Likewise.
Found by Valgrind.
This commit is contained in:
Pavel Roskin 2003-09-22 19:40:07 +00:00
parent 99a4576359
commit 4014009077
4 changed files with 19 additions and 12 deletions

View File

@ -1,3 +1,11 @@
2003-09-22 Pavel Roskin <proski@gnu.org>
* menu.c (menu_scan_hotkey): Use g_strlcpy() to avoid undefined
behavior when using strcpy() on overlapping strings.
* profile.c (GetSetProfile): Likewise.
* widget.c (button_scan_hotkey): Likewise.
Found by Valgrind.
2003-09-13 Pavel Roskin <proski@gnu.org> 2003-09-13 Pavel Roskin <proski@gnu.org>
* dlg.c (dlg_replace_widget): Clean rewrite. It was broken * dlg.c (dlg_replace_widget): Clean rewrite. It was broken

View File

@ -39,10 +39,9 @@ menu_scan_hotkey(Menu *menu)
char *cp = strchr (menu->name, '&'); char *cp = strchr (menu->name, '&');
if (cp != NULL && cp[1] != '\0') { if (cp != NULL && cp[1] != '\0') {
strcpy (cp, cp+1); g_strlcpy (cp, cp + 1, strlen (cp));
menu->hotkey = tolower (*cp); menu->hotkey = tolower (*cp);
} } else
else
menu->hotkey = 0; menu->hotkey = 0;
} }

View File

@ -329,7 +329,7 @@ static short GetSetProfile (int set, const char * AppName, char * KeyName,
s = GetSetProfileChar (set, AppName, KeyName, Default, FileName); s = GetSetProfileChar (set, AppName, KeyName, Default, FileName);
if (!set){ if (!set){
ReturnedString [Size-1] = 0; ReturnedString [Size-1] = 0;
strncpy (ReturnedString, s, Size-1); g_strlcpy (ReturnedString, s, Size-1);
} }
return 1; return 1;
} }

View File

@ -206,7 +206,7 @@ button_scan_hotkey(WButton* b)
char *cp = strchr (b->text, '&'); char *cp = strchr (b->text, '&');
if (cp != NULL && cp[1] != '\0') { if (cp != NULL && cp[1] != '\0') {
strcpy (cp, cp+1); g_strlcpy (cp, cp + 1, strlen (cp));
b->hotkey = tolower (*cp); b->hotkey = tolower (*cp);
b->hotpos = cp - b->text; b->hotpos = cp - b->text;
} }