summaryrefslogtreecommitdiff
path: root/apps/cuesheet.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-11-14 11:32:34 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2022-11-14 23:56:16 -0500
commitf6c719d7ec71cc7771c46d3daa390924a3871ba3 (patch)
treee6209f23565db01809f75067247e667963092ff6 /apps/cuesheet.c
parentb25a9d8f99b75570d18ea64602de7fe48da612d6 (diff)
downloadrockbox-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/cuesheet.c')
-rw-r--r--apps/cuesheet.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/apps/cuesheet.c b/apps/cuesheet.c
index da14147262..561be6a677 100644
--- a/apps/cuesheet.c
+++ b/apps/cuesheet.c
@@ -58,7 +58,7 @@ static bool search_for_cuesheet(const char *path, struct cuesheet_file *cue_file
58 slash_cuepath = &cuepath[slash - path]; 58 slash_cuepath = &cuepath[slash - path];
59 dot = strrchr(slash_cuepath, '.'); 59 dot = strrchr(slash_cuepath, '.');
60 if (dot) 60 if (dot)
61 strlcpy(dot, ".cue", MAX_PATH - (dot-cuepath)); 61 strmemccpy(dot, ".cue", MAX_PATH - (dot-cuepath));
62 62
63 if (!dot || !file_exists(cuepath)) 63 if (!dot || !file_exists(cuepath))
64 { 64 {
@@ -72,14 +72,14 @@ static bool search_for_cuesheet(const char *path, struct cuesheet_file *cue_file
72skip: 72skip:
73 if ((len+4) >= MAX_PATH) 73 if ((len+4) >= MAX_PATH)
74 return false; 74 return false;
75 strlcpy(cuepath, path, MAX_PATH); 75 strmemccpy(cuepath, path, MAX_PATH);
76 strlcat(cuepath, ".cue", MAX_PATH); 76 strlcat(cuepath, ".cue", MAX_PATH);
77 if (!file_exists(cuepath)) 77 if (!file_exists(cuepath))
78 return false; 78 return false;
79 } 79 }
80 } 80 }
81 81
82 strlcpy(cue_file->path, cuepath, MAX_PATH); 82 strmemccpy(cue_file->path, cuepath, MAX_PATH);
83 return true; 83 return true;
84} 84}
85 85
@@ -91,7 +91,7 @@ bool look_for_cuesheet_file(struct mp3entry *track_id3, struct cuesheet_file *cu
91 cue_file->pos = track_id3->embedded_cuesheet.pos; 91 cue_file->pos = track_id3->embedded_cuesheet.pos;
92 cue_file->size = track_id3->embedded_cuesheet.size; 92 cue_file->size = track_id3->embedded_cuesheet.size;
93 cue_file->encoding = track_id3->embedded_cuesheet.encoding; 93 cue_file->encoding = track_id3->embedded_cuesheet.encoding;
94 strlcpy(cue_file->path, track_id3->path, MAX_PATH); 94 strmemccpy(cue_file->path, track_id3->path, MAX_PATH);
95 return true; 95 return true;
96 } 96 }
97 97
@@ -363,7 +363,7 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
363 } 363 }
364 else 364 else
365 { 365 {
366 strlcpy(dest, string, count); 366 strmemccpy(dest, string, count);
367 } 367 }
368 } 368 }
369 } 369 }
@@ -386,7 +386,7 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
386 strcpy(cue->file, cue->path); 386 strcpy(cue->file, cue->path);
387 char *slash = strrchr(cue->file, '/'); 387 char *slash = strrchr(cue->file, '/');
388 if (!slash++) slash = cue->file; 388 if (!slash++) slash = cue->file;
389 strlcpy(slash, line, MAX_PATH - (slash - cue->file)); 389 strmemccpy(slash, line, MAX_PATH - (slash - cue->file));
390 } 390 }
391 391
392 /* If some songs don't have performer info, we copy the cuesheet performer */ 392 /* If some songs don't have performer info, we copy the cuesheet performer */
@@ -394,10 +394,10 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
394 for (i = 0; i < cue->track_count; i++) 394 for (i = 0; i < cue->track_count; i++)
395 { 395 {
396 if (*(cue->tracks[i].performer) == '\0') 396 if (*(cue->tracks[i].performer) == '\0')
397 strlcpy(cue->tracks[i].performer, cue->performer, MAX_NAME*3); 397 strmemccpy(cue->tracks[i].performer, cue->performer, MAX_NAME*3);
398 398
399 if (*(cue->tracks[i].songwriter) == '\0') 399 if (*(cue->tracks[i].songwriter) == '\0')
400 strlcpy(cue->tracks[i].songwriter, cue->songwriter, MAX_NAME*3); 400 strmemccpy(cue->tracks[i].songwriter, cue->songwriter, MAX_NAME*3);
401 } 401 }
402 402
403 return true; 403 return true;
@@ -441,7 +441,7 @@ static const char* list_get_name_cb(int selected_item,
441 struct cuesheet *cue = (struct cuesheet *)data; 441 struct cuesheet *cue = (struct cuesheet *)data;
442 442
443 if (selected_item & 1) 443 if (selected_item & 1)
444 strlcpy(buffer, cue->tracks[selected_item/2].title, buffer_len); 444 strmemccpy(buffer, cue->tracks[selected_item/2].title, buffer_len);
445 else 445 else
446 snprintf(buffer, buffer_len, "%02d. %s", selected_item/2+1, 446 snprintf(buffer, buffer_len, "%02d. %s", selected_item/2+1,
447 cue->tracks[selected_item/2].performer); 447 cue->tracks[selected_item/2].performer);
@@ -508,7 +508,7 @@ void browse_cuesheet(struct cuesheet *cue)
508 /* check that this cue is the same one that would be found by 508 /* check that this cue is the same one that would be found by
509 a search from playback */ 509 a search from playback */
510 char file[MAX_PATH]; 510 char file[MAX_PATH];
511 strlcpy(file, cue->file, MAX_PATH); 511 strmemccpy(file, cue->file, MAX_PATH);
512 512
513 if (!strcmp(cue->path, file) || /* if embedded */ 513 if (!strcmp(cue->path, file) || /* if embedded */
514 (search_for_cuesheet(file, &cue_file) && 514 (search_for_cuesheet(file, &cue_file) &&
@@ -535,7 +535,7 @@ bool display_cuesheet_content(char* filename)
535 if (!cue || bufsize < sizeof(struct cuesheet)) 535 if (!cue || bufsize < sizeof(struct cuesheet))
536 return false; 536 return false;
537 537
538 strlcpy(cue_file.path, filename, MAX_PATH); 538 strmemccpy(cue_file.path, filename, MAX_PATH);
539 cue_file.pos = 0; 539 cue_file.pos = 0;
540 cue_file.size = 0; 540 cue_file.size = 0;
541 541