diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-11-14 11:32:34 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2022-11-14 23:56:16 -0500 |
commit | f6c719d7ec71cc7771c46d3daa390924a3871ba3 (patch) | |
tree | e6209f23565db01809f75067247e667963092ff6 /apps/settings.c | |
parent | b25a9d8f99b75570d18ea64602de7fe48da612d6 (diff) | |
download | rockbox-f6c719d7ec71cc7771c46d3daa390924a3871ba3.tar.gz rockbox-f6c719d7ec71cc7771c46d3daa390924a3871ba3.zip |
replace strlcpy with strmemccpy
replace applicable calls to strlcpy with calls to strmemccpy
which null terminates on truncation
in theory the strmemccpy calls should be slightly faster since they
don't traverse the rest of the source string on truncation
but I seriously doubt there is too much of that going on in the code base
Change-Id: Ia0251514e36a6242bbf3f03c5e0df123aba60ed2
Diffstat (limited to 'apps/settings.c')
-rw-r--r-- | apps/settings.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/apps/settings.c b/apps/settings.c index edf4d2b13f..7c4dc4d124 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -35,8 +35,7 @@ | |||
35 | #include "backlight.h" | 35 | #include "backlight.h" |
36 | #include "audio.h" | 36 | #include "audio.h" |
37 | #include "talk.h" | 37 | #include "talk.h" |
38 | #include "strlcpy.h" | 38 | #include "string-extra.h" |
39 | #include "strcasestr.h" | ||
40 | #include "rtc.h" | 39 | #include "rtc.h" |
41 | #include "power.h" | 40 | #include "power.h" |
42 | #include "ata_idle_notify.h" | 41 | #include "ata_idle_notify.h" |
@@ -251,7 +250,7 @@ bool cfg_string_to_int(int setting_id, int* out, const char* str) | |||
251 | } | 250 | } |
252 | else return false; | 251 | else return false; |
253 | } | 252 | } |
254 | strlcpy(temp, start, end-start+1); | 253 | strmemccpy(temp, start, end-start+1); |
255 | if (!strcmp(str, temp)) | 254 | if (!strcmp(str, temp)) |
256 | { | 255 | { |
257 | *out = count; | 256 | *out = count; |
@@ -343,18 +342,22 @@ bool settings_load_config(const char* file, bool apply) | |||
343 | size_t len = strlen(dir); | 342 | size_t len = strlen(dir); |
344 | if (!strncasecmp(value, dir, len)) | 343 | if (!strncasecmp(value, dir, len)) |
345 | { | 344 | { |
346 | strlcpy(storage, &value[len], MAX_PATH); | 345 | strmemccpy(storage, &value[len], MAX_PATH); |
347 | } | 346 | } |
348 | else strlcpy(storage, value, MAX_PATH); | 347 | else |
348 | strmemccpy(storage, value, MAX_PATH); | ||
349 | |||
349 | } | 350 | } |
350 | else strlcpy(storage, value, MAX_PATH); | 351 | else |
352 | strmemccpy(storage, value, MAX_PATH); | ||
353 | |||
351 | if (settings[i].filename_setting->suffix) | 354 | if (settings[i].filename_setting->suffix) |
352 | { | 355 | { |
353 | char *s = strcasestr(storage,settings[i].filename_setting->suffix); | 356 | char *s = strcasestr(storage,settings[i].filename_setting->suffix); |
354 | if (s) *s = '\0'; | 357 | if (s) *s = '\0'; |
355 | } | 358 | } |
356 | strlcpy((char*)settings[i].setting, storage, | 359 | strmemccpy((char*)settings[i].setting, storage, |
357 | settings[i].filename_setting->max_len); | 360 | settings[i].filename_setting->max_len); |
358 | break; | 361 | break; |
359 | } | 362 | } |
360 | } | 363 | } |
@@ -393,11 +396,11 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len) | |||
393 | if (value[count] == val) | 396 | if (value[count] == val) |
394 | { | 397 | { |
395 | if (end == NULL) | 398 | if (end == NULL) |
396 | strlcpy(buf, start, buf_len); | 399 | strmemccpy(buf, start, buf_len); |
397 | else | 400 | else |
398 | { | 401 | { |
399 | int len = MIN(buf_len, (end-start) + 1); | 402 | int len = MIN(buf_len, (end-start) + 1); |
400 | strlcpy(buf, start, len); | 403 | strmemccpy(buf, start, len); |
401 | } | 404 | } |
402 | return true; | 405 | return true; |
403 | } | 406 | } |
@@ -421,11 +424,11 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len) | |||
421 | } | 424 | } |
422 | end = strchr(start,','); | 425 | end = strchr(start,','); |
423 | if (end == NULL) | 426 | if (end == NULL) |
424 | strlcpy(buf, start, buf_len); | 427 | strmemccpy(buf, start, buf_len); |
425 | else | 428 | else |
426 | { | 429 | { |
427 | int len = MIN(buf_len, (end-start) + 1); | 430 | int len = MIN(buf_len, (end-start) + 1); |
428 | strlcpy(buf, start, len); | 431 | strmemccpy(buf, start, len); |
429 | } | 432 | } |
430 | return true; | 433 | return true; |
431 | } | 434 | } |
@@ -491,7 +494,7 @@ bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len) | |||
491 | else | 494 | else |
492 | { | 495 | { |
493 | int len = MIN(buf_len, settings[i].filename_setting->max_len); | 496 | int len = MIN(buf_len, settings[i].filename_setting->max_len); |
494 | strlcpy(buf,(char*)settings[i].setting,len); | 497 | strmemccpy(buf,(char*)settings[i].setting,len); |
495 | } | 498 | } |
496 | break; | 499 | break; |
497 | } /* switch () */ | 500 | } /* switch () */ |
@@ -1071,8 +1074,8 @@ void reset_setting(const struct settings_list *setting, void *var) | |||
1071 | break; | 1074 | break; |
1072 | case F_T_CHARPTR: | 1075 | case F_T_CHARPTR: |
1073 | case F_T_UCHARPTR: | 1076 | case F_T_UCHARPTR: |
1074 | strlcpy((char*)var, setting->default_val.charptr, | 1077 | strmemccpy((char*)var, setting->default_val.charptr, |
1075 | setting->filename_setting->max_len); | 1078 | setting->filename_setting->max_len); |
1076 | break; | 1079 | break; |
1077 | } | 1080 | } |
1078 | } | 1081 | } |
@@ -1265,6 +1268,6 @@ void set_file(const char* filename, char* setting, const int maxlen) | |||
1265 | if (len > maxlen) | 1268 | if (len > maxlen) |
1266 | return; | 1269 | return; |
1267 | 1270 | ||
1268 | strlcpy(setting, fptr, len); | 1271 | strmemccpy(setting, fptr, len); |
1269 | settings_save(); | 1272 | settings_save(); |
1270 | } | 1273 | } |