diff options
author | Nils Wallménius <nils@rockbox.org> | 2009-07-14 13:57:45 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2009-07-14 13:57:45 +0000 |
commit | 3d4701a6e41616cf581a297bab1451cf2db70249 (patch) | |
tree | f845837c96ffbed7d59ddf8308f3b3e7c40cb8c9 /apps/gui | |
parent | c2900a1bacd5d98b57a0d15ea2add1bc08764057 (diff) | |
download | rockbox-3d4701a6e41616cf581a297bab1451cf2db70249.tar.gz rockbox-3d4701a6e41616cf581a297bab1451cf2db70249.zip |
FS#10080
* Move strncpy() from core to the pluginlib
* Introduce strlcpy() and use that instead in most places (use memcpy in a few) in core and some plugins
* Drop strncpy() from the codec api as no codec used it
* Bump codec and plugin api versions
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21863 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/buttonbar.c | 9 | ||||
-rw-r--r-- | apps/gui/gwps-common.c | 11 | ||||
-rw-r--r-- | apps/gui/option_select.c | 6 | ||||
-rw-r--r-- | apps/gui/statusbar.c | 7 | ||||
-rw-r--r-- | apps/gui/wps_parser.c | 9 |
5 files changed, 17 insertions, 25 deletions
diff --git a/apps/gui/buttonbar.c b/apps/gui/buttonbar.c index abf1800bb2..3c343f09ac 100644 --- a/apps/gui/buttonbar.c +++ b/apps/gui/buttonbar.c | |||
@@ -86,18 +86,15 @@ void gui_buttonbar_set(struct gui_buttonbar * buttonbar, | |||
86 | gui_buttonbar_unset(buttonbar); | 86 | gui_buttonbar_unset(buttonbar); |
87 | if(caption1) | 87 | if(caption1) |
88 | { | 88 | { |
89 | strncpy(buttonbar->caption[0], caption1, 7); | 89 | strlcpy(buttonbar->caption[0], caption1, BUTTONBAR_CAPTION_LENGTH); |
90 | buttonbar->caption[0][7] = 0; | ||
91 | } | 90 | } |
92 | if(caption2) | 91 | if(caption2) |
93 | { | 92 | { |
94 | strncpy(buttonbar->caption[1], caption2, 7); | 93 | strlcpy(buttonbar->caption[1], caption2, BUTTONBAR_CAPTION_LENGTH); |
95 | buttonbar->caption[1][7] = 0; | ||
96 | } | 94 | } |
97 | if(caption3) | 95 | if(caption3) |
98 | { | 96 | { |
99 | strncpy(buttonbar->caption[2], caption3, 7); | 97 | strlcpy(buttonbar->caption[2], caption3, BUTTONBAR_CAPTION_LENGTH); |
100 | buttonbar->caption[2][7] = 0; | ||
101 | } | 98 | } |
102 | } | 99 | } |
103 | 100 | ||
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index f480f616a2..c0923a9ab5 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c | |||
@@ -659,8 +659,7 @@ static char* get_dir(char* buf, int buf_size, const char* path, int level) | |||
659 | return NULL; | 659 | return NULL; |
660 | 660 | ||
661 | len = MIN(last_sep - sep, buf_size - 1); | 661 | len = MIN(last_sep - sep, buf_size - 1); |
662 | strncpy(buf, sep + 1, len); | 662 | strlcpy(buf, sep + 1, len + 1); |
663 | buf[len] = 0; | ||
664 | return buf; | 663 | return buf; |
665 | } | 664 | } |
666 | 665 | ||
@@ -1183,12 +1182,12 @@ static const char *get_token_value(struct gui_wps *gwps, | |||
1183 | { | 1182 | { |
1184 | /* we need 11 characters (full line) for | 1183 | /* we need 11 characters (full line) for |
1185 | progress-bar */ | 1184 | progress-bar */ |
1186 | strncpy(buf, " ", buf_size); | 1185 | strlcpy(buf, " ", buf_size); |
1187 | } | 1186 | } |
1188 | else | 1187 | else |
1189 | { | 1188 | { |
1190 | /* Tell the user if we have an OldPlayer */ | 1189 | /* Tell the user if we have an OldPlayer */ |
1191 | strncpy(buf, " <Old LCD> ", buf_size); | 1190 | strlcpy(buf, " <Old LCD> ", buf_size); |
1192 | } | 1191 | } |
1193 | return buf; | 1192 | return buf; |
1194 | #endif | 1193 | #endif |
@@ -1254,11 +1253,11 @@ static const char *get_token_value(struct gui_wps *gwps, | |||
1254 | break; | 1253 | break; |
1255 | case 2: | 1254 | case 2: |
1256 | case 4: | 1255 | case 4: |
1257 | strncpy(buf, id3->track_gain_string, buf_size); | 1256 | strlcpy(buf, id3->track_gain_string, buf_size); |
1258 | break; | 1257 | break; |
1259 | case 3: | 1258 | case 3: |
1260 | case 5: | 1259 | case 5: |
1261 | strncpy(buf, id3->album_gain_string, buf_size); | 1260 | strlcpy(buf, id3->album_gain_string, buf_size); |
1262 | break; | 1261 | break; |
1263 | } | 1262 | } |
1264 | return buf; | 1263 | return buf; |
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index 7b6c489bf3..01259c4136 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c | |||
@@ -76,7 +76,7 @@ char *option_get_valuestring(const struct settings_list *setting, | |||
76 | if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) | 76 | if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) |
77 | { | 77 | { |
78 | bool val = (bool)temp_var; | 78 | bool val = (bool)temp_var; |
79 | strncpy(buffer, str(val? setting->bool_setting->lang_yes : | 79 | strlcpy(buffer, str(val? setting->bool_setting->lang_yes : |
80 | setting->bool_setting->lang_no), buf_len); | 80 | setting->bool_setting->lang_no), buf_len); |
81 | } | 81 | } |
82 | #if 0 /* probably dont need this one */ | 82 | #if 0 /* probably dont need this one */ |
@@ -137,7 +137,7 @@ char *option_get_valuestring(const struct settings_list *setting, | |||
137 | const struct choice_setting *info = setting->choice_setting; | 137 | const struct choice_setting *info = setting->choice_setting; |
138 | if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY) | 138 | if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY) |
139 | { | 139 | { |
140 | strncpy(buffer, str(info->talks[(int)temp_var]), buf_len); | 140 | strlcpy(buffer, str(info->talks[(int)temp_var]), buf_len); |
141 | } | 141 | } |
142 | else | 142 | else |
143 | { | 143 | { |
@@ -149,7 +149,7 @@ char *option_get_valuestring(const struct settings_list *setting, | |||
149 | { | 149 | { |
150 | int value= (int)temp_var; | 150 | int value= (int)temp_var; |
151 | char *val = P2STR(setting->choice_setting->desc[value]); | 151 | char *val = P2STR(setting->choice_setting->desc[value]); |
152 | strncpy(buffer, val, buf_len); | 152 | strlcpy(buffer, val, buf_len); |
153 | } | 153 | } |
154 | } | 154 | } |
155 | return buffer; | 155 | return buffer; |
diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c index 47dcb4ead1..5e215090f5 100644 --- a/apps/gui/statusbar.c +++ b/apps/gui/statusbar.c | |||
@@ -617,7 +617,7 @@ static void gui_statusbar_time(struct screen * display, struct tm *time) | |||
617 | snprintf(buffer, sizeof(buffer), "%02d:%02d", hour, minute); | 617 | snprintf(buffer, sizeof(buffer), "%02d:%02d", hour, minute); |
618 | } | 618 | } |
619 | else { | 619 | else { |
620 | strncpy(buffer, "--:--", sizeof buffer); | 620 | strlcpy(buffer, "--:--", sizeof(buffer)); |
621 | } | 621 | } |
622 | display->setfont(FONT_SYSFIXED); | 622 | display->setfont(FONT_SYSFIXED); |
623 | display->getstringsize(buffer, &width, &height); | 623 | display->getstringsize(buffer, &width, &height); |
@@ -626,7 +626,6 @@ static void gui_statusbar_time(struct screen * display, struct tm *time) | |||
626 | STATUSBAR_Y_POS, buffer); | 626 | STATUSBAR_Y_POS, buffer); |
627 | } | 627 | } |
628 | display->setfont(FONT_UI); | 628 | display->setfont(FONT_UI); |
629 | |||
630 | } | 629 | } |
631 | #endif | 630 | #endif |
632 | 631 | ||
@@ -758,14 +757,14 @@ static void gui_statusbar_icon_recording_info(struct screen * display) | |||
758 | if (global_settings.rec_source == AUDIO_SRC_SPDIF) | 757 | if (global_settings.rec_source == AUDIO_SRC_SPDIF) |
759 | { | 758 | { |
760 | /* Can't measure S/PDIF sample rate on Archos/Sim yet */ | 759 | /* Can't measure S/PDIF sample rate on Archos/Sim yet */ |
761 | strncpy(buffer, "--", sizeof(buffer)); | 760 | strlcpy(buffer, "--", sizeof(buffer)); |
762 | } | 761 | } |
763 | else | 762 | else |
764 | #endif /* HAVE_SPDIF_IN */ | 763 | #endif /* HAVE_SPDIF_IN */ |
765 | { | 764 | { |
766 | static char const * const freq_strings[12] = | 765 | static char const * const freq_strings[12] = |
767 | { "44", "48", "32", "22", "24", "16" }; | 766 | { "44", "48", "32", "22", "24", "16" }; |
768 | strncpy(buffer, freq_strings[global_settings.rec_frequency], | 767 | strlcpy(buffer, freq_strings[global_settings.rec_frequency], |
769 | sizeof(buffer)); | 768 | sizeof(buffer)); |
770 | } | 769 | } |
771 | 770 | ||
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c index 09bcab8443..8ae83924c2 100644 --- a/apps/gui/wps_parser.c +++ b/apps/gui/wps_parser.c | |||
@@ -1489,8 +1489,7 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr) | |||
1489 | break; | 1489 | break; |
1490 | } | 1490 | } |
1491 | 1491 | ||
1492 | strncpy(stringbuf, string_start, len); | 1492 | strlcpy(stringbuf, string_start, len+1); |
1493 | *(stringbuf + len) = '\0'; | ||
1494 | 1493 | ||
1495 | data->strings[data->num_strings] = stringbuf; | 1494 | data->strings[data->num_strings] = stringbuf; |
1496 | stringbuf += len + 1; | 1495 | stringbuf += len + 1; |
@@ -1781,11 +1780,9 @@ bool wps_data_load(struct wps_data *wps_data, | |||
1781 | #ifdef HAVE_LCD_BITMAP | 1780 | #ifdef HAVE_LCD_BITMAP |
1782 | /* get the bitmap dir */ | 1781 | /* get the bitmap dir */ |
1783 | char bmpdir[MAX_PATH]; | 1782 | char bmpdir[MAX_PATH]; |
1784 | size_t bmpdirlen; | ||
1785 | char *dot = strrchr(buf, '.'); | 1783 | char *dot = strrchr(buf, '.'); |
1786 | bmpdirlen = dot - buf; | 1784 | |
1787 | strncpy(bmpdir, buf, dot - buf); | 1785 | strlcpy(bmpdir, buf, dot - buf + 1); |
1788 | bmpdir[bmpdirlen] = 0; | ||
1789 | 1786 | ||
1790 | /* load the bitmaps that were found by the parsing */ | 1787 | /* load the bitmaps that were found by the parsing */ |
1791 | if (!load_wps_bitmaps(wps_data, bmpdir)) { | 1788 | if (!load_wps_bitmaps(wps_data, bmpdir)) { |