* 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>
* dlg.c (dlg_replace_widget): Clean rewrite. It was broken

View File

@ -34,15 +34,14 @@
int menubar_visible = 1; /* This is the new default */
static void
menu_scan_hotkey(Menu *menu)
menu_scan_hotkey (Menu *menu)
{
char* cp = strchr (menu->name, '&');
char *cp = strchr (menu->name, '&');
if (cp != NULL && cp[1] != '\0'){
strcpy (cp, cp+1);
menu->hotkey = tolower(*cp);
}
else
if (cp != NULL && cp[1] != '\0') {
g_strlcpy (cp, cp + 1, strlen (cp));
menu->hotkey = tolower (*cp);
} else
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);
if (!set){
ReturnedString [Size-1] = 0;
strncpy (ReturnedString, s, Size-1);
g_strlcpy (ReturnedString, s, Size-1);
}
return 1;
}

View File

@ -201,12 +201,12 @@ button_len (const char *text, unsigned int flags)
* the button text is g_malloc()ed, we can safely change and shorten it.
*/
static void
button_scan_hotkey(WButton* b)
button_scan_hotkey (WButton *b)
{
char* cp = strchr (b->text, '&');
char *cp = strchr (b->text, '&');
if (cp != NULL && cp[1] != '\0'){
strcpy (cp, cp+1);
if (cp != NULL && cp[1] != '\0') {
g_strlcpy (cp, cp + 1, strlen (cp));
b->hotkey = tolower (*cp);
b->hotpos = cp - b->text;
}