1
0
Fork 0
forked from len0rd/rockbox
* 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
This commit is contained in:
Nils Wallménius 2009-07-14 13:57:45 +00:00
parent c2900a1bac
commit 3d4701a6e4
83 changed files with 271 additions and 271 deletions

View file

@ -1002,17 +1002,14 @@ static bool parse_bookmark(const char *bookmark,
if (resume_file != NULL) if (resume_file != NULL)
{ {
size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s); size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s);
len = MIN(resume_file_size - 1, len); len = MIN(resume_file_size - 1, len);
strncpy(resume_file, s, len); strlcpy(resume_file, s, len + 1);
resume_file[len] = 0;
} }
if (end != NULL && file_name != NULL) if (end != NULL && file_name != NULL)
{ {
end++; end++;
strncpy(file_name, end, MAX_PATH - 1); strlcpy(file_name, end, MAX_PATH);
file_name[MAX_PATH - 1] = 0;
} }
return true; return true;

View file

@ -919,7 +919,7 @@ int bufopen(const char *file, size_t offset, enum data_type type)
h->widx = buf_widx; h->widx = buf_widx;
h->available = 0; h->available = 0;
h->type = type; h->type = type;
strncpy(h->path, file, MAX_PATH); strlcpy(h->path, file, MAX_PATH);
buf_widx += sizeof(struct mp3entry); /* safe because the handle buf_widx += sizeof(struct mp3entry); /* safe because the handle
can't wrap */ can't wrap */
@ -952,7 +952,7 @@ int bufopen(const char *file, size_t offset, enum data_type type)
return ERR_BUFFER_FULL; return ERR_BUFFER_FULL;
} }
strncpy(h->path, file, MAX_PATH); strlcpy(h->path, file, MAX_PATH);
h->offset = adjusted_offset; h->offset = adjusted_offset;
h->ridx = buf_widx; h->ridx = buf_widx;
h->widx = buf_widx; h->widx = buf_widx;

View file

@ -122,7 +122,6 @@ struct codec_api ci = {
/* strings and memory */ /* strings and memory */
strcpy, strcpy,
strncpy,
strlen, strlen,
strcmp, strcmp,
strcat, strcat,

View file

@ -75,12 +75,12 @@
#define CODEC_ENC_MAGIC 0x52454E43 /* RENC */ #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
/* increase this every time the api struct changes */ /* increase this every time the api struct changes */
#define CODEC_API_VERSION 32 #define CODEC_API_VERSION 33
/* update this to latest version if a change to the api struct breaks /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ new function which are "waiting" at the end of the function table) */
#define CODEC_MIN_API_VERSION 32 #define CODEC_MIN_API_VERSION 33
/* codec return codes */ /* codec return codes */
enum codec_status { enum codec_status {
@ -180,7 +180,6 @@ struct codec_api {
/* strings and memory */ /* strings and memory */
char* (*strcpy)(char *dst, const char *src); char* (*strcpy)(char *dst, const char *src);
char* (*strncpy)(char *dst, const char *src, size_t length);
size_t (*strlen)(const char *str); size_t (*strlen)(const char *str);
int (*strcmp)(const char *, const char *); int (*strcmp)(const char *, const char *);
char *(*strcat)(char *s1, const char *s2); char *(*strcat)(char *s1, const char *s2);

View file

@ -84,7 +84,7 @@ bool look_for_cuesheet_file(const char *trackpath, char *found_cue_path)
return false; return false;
} }
strncpy(cuepath, trackpath, MAX_PATH); strlcpy(cuepath, trackpath, MAX_PATH);
dot = strrchr(cuepath, '.'); dot = strrchr(cuepath, '.');
strcpy(dot, ".cue"); strcpy(dot, ".cue");
@ -103,7 +103,7 @@ bool look_for_cuesheet_file(const char *trackpath, char *found_cue_path)
} }
if (found_cue_path) if (found_cue_path)
strncpy(found_cue_path, cuepath, MAX_PATH); strlcpy(found_cue_path, cuepath, MAX_PATH);
return true; return true;
} }
@ -205,8 +205,7 @@ bool parse_cuesheet(char *file, struct cuesheet *cue)
} }
else else
{ {
strncpy(dest, string, MAX_NAME*3); strlcpy(dest, string, MAX_NAME*3 + 1);
dest[MAX_NAME*3] = '\0';
} }
} }
} }
@ -218,10 +217,10 @@ bool parse_cuesheet(char *file, struct cuesheet *cue)
for (i = 0; i < cue->track_count; i++) for (i = 0; i < cue->track_count; i++)
{ {
if (*(cue->tracks[i].performer) == '\0') if (*(cue->tracks[i].performer) == '\0')
strncpy(cue->tracks[i].performer, cue->performer, MAX_NAME*3); strlcpy(cue->tracks[i].performer, cue->performer, MAX_NAME*3);
if (*(cue->tracks[i].songwriter) == '\0') if (*(cue->tracks[i].songwriter) == '\0')
strncpy(cue->tracks[i].songwriter, cue->songwriter, MAX_NAME*3); strlcpy(cue->tracks[i].songwriter, cue->songwriter, MAX_NAME*3);
} }
return true; return true;
@ -271,7 +270,7 @@ static char *list_get_name_cb(int selected_item,
struct cuesheet *cue = (struct cuesheet *)data; struct cuesheet *cue = (struct cuesheet *)data;
if (selected_item & 1) if (selected_item & 1)
strncpy(buffer, cue->tracks[selected_item/2].title, buffer_len); strlcpy(buffer, cue->tracks[selected_item/2].title, buffer_len);
else else
snprintf(buffer, buffer_len, "%02d. %s", selected_item/2+1, snprintf(buffer, buffer_len, "%02d. %s", selected_item/2+1,
cue->tracks[selected_item/2].performer); cue->tracks[selected_item/2].performer);

View file

@ -1910,8 +1910,7 @@ static int disk_callback(int btn, struct gui_synclist *lists)
if (card->initialized > 0) if (card->initialized > 0)
{ {
card_name[6] = '\0'; strlcpy(card_name, ((unsigned char*)card->cid) + 3, sizeof(card_name));
strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
simplelist_addline(SIMPLELIST_ADD_LINE, simplelist_addline(SIMPLELIST_ADD_LINE,
"%s Rev %d.%d", card_name, "%s Rev %d.%d", card_name,
(int) card_extract_bits(card->cid, 55, 4), (int) card_extract_bits(card->cid, 55, 4),

View file

@ -86,18 +86,15 @@ void gui_buttonbar_set(struct gui_buttonbar * buttonbar,
gui_buttonbar_unset(buttonbar); gui_buttonbar_unset(buttonbar);
if(caption1) if(caption1)
{ {
strncpy(buttonbar->caption[0], caption1, 7); strlcpy(buttonbar->caption[0], caption1, BUTTONBAR_CAPTION_LENGTH);
buttonbar->caption[0][7] = 0;
} }
if(caption2) if(caption2)
{ {
strncpy(buttonbar->caption[1], caption2, 7); strlcpy(buttonbar->caption[1], caption2, BUTTONBAR_CAPTION_LENGTH);
buttonbar->caption[1][7] = 0;
} }
if(caption3) if(caption3)
{ {
strncpy(buttonbar->caption[2], caption3, 7); strlcpy(buttonbar->caption[2], caption3, BUTTONBAR_CAPTION_LENGTH);
buttonbar->caption[2][7] = 0;
} }
} }

View file

@ -659,8 +659,7 @@ static char* get_dir(char* buf, int buf_size, const char* path, int level)
return NULL; return NULL;
len = MIN(last_sep - sep, buf_size - 1); len = MIN(last_sep - sep, buf_size - 1);
strncpy(buf, sep + 1, len); strlcpy(buf, sep + 1, len + 1);
buf[len] = 0;
return buf; return buf;
} }
@ -1183,12 +1182,12 @@ static const char *get_token_value(struct gui_wps *gwps,
{ {
/* we need 11 characters (full line) for /* we need 11 characters (full line) for
progress-bar */ progress-bar */
strncpy(buf, " ", buf_size); strlcpy(buf, " ", buf_size);
} }
else else
{ {
/* Tell the user if we have an OldPlayer */ /* Tell the user if we have an OldPlayer */
strncpy(buf, " <Old LCD> ", buf_size); strlcpy(buf, " <Old LCD> ", buf_size);
} }
return buf; return buf;
#endif #endif
@ -1254,11 +1253,11 @@ static const char *get_token_value(struct gui_wps *gwps,
break; break;
case 2: case 2:
case 4: case 4:
strncpy(buf, id3->track_gain_string, buf_size); strlcpy(buf, id3->track_gain_string, buf_size);
break; break;
case 3: case 3:
case 5: case 5:
strncpy(buf, id3->album_gain_string, buf_size); strlcpy(buf, id3->album_gain_string, buf_size);
break; break;
} }
return buf; return buf;

View file

@ -76,7 +76,7 @@ char *option_get_valuestring(const struct settings_list *setting,
if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
{ {
bool val = (bool)temp_var; bool val = (bool)temp_var;
strncpy(buffer, str(val? setting->bool_setting->lang_yes : strlcpy(buffer, str(val? setting->bool_setting->lang_yes :
setting->bool_setting->lang_no), buf_len); setting->bool_setting->lang_no), buf_len);
} }
#if 0 /* probably dont need this one */ #if 0 /* probably dont need this one */
@ -137,7 +137,7 @@ char *option_get_valuestring(const struct settings_list *setting,
const struct choice_setting *info = setting->choice_setting; const struct choice_setting *info = setting->choice_setting;
if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY) if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY)
{ {
strncpy(buffer, str(info->talks[(int)temp_var]), buf_len); strlcpy(buffer, str(info->talks[(int)temp_var]), buf_len);
} }
else else
{ {
@ -149,7 +149,7 @@ char *option_get_valuestring(const struct settings_list *setting,
{ {
int value= (int)temp_var; int value= (int)temp_var;
char *val = P2STR(setting->choice_setting->desc[value]); char *val = P2STR(setting->choice_setting->desc[value]);
strncpy(buffer, val, buf_len); strlcpy(buffer, val, buf_len);
} }
} }
return buffer; return buffer;

View file

@ -617,7 +617,7 @@ static void gui_statusbar_time(struct screen * display, struct tm *time)
snprintf(buffer, sizeof(buffer), "%02d:%02d", hour, minute); snprintf(buffer, sizeof(buffer), "%02d:%02d", hour, minute);
} }
else { else {
strncpy(buffer, "--:--", sizeof buffer); strlcpy(buffer, "--:--", sizeof(buffer));
} }
display->setfont(FONT_SYSFIXED); display->setfont(FONT_SYSFIXED);
display->getstringsize(buffer, &width, &height); display->getstringsize(buffer, &width, &height);
@ -626,7 +626,6 @@ static void gui_statusbar_time(struct screen * display, struct tm *time)
STATUSBAR_Y_POS, buffer); STATUSBAR_Y_POS, buffer);
} }
display->setfont(FONT_UI); display->setfont(FONT_UI);
} }
#endif #endif
@ -758,14 +757,14 @@ static void gui_statusbar_icon_recording_info(struct screen * display)
if (global_settings.rec_source == AUDIO_SRC_SPDIF) if (global_settings.rec_source == AUDIO_SRC_SPDIF)
{ {
/* Can't measure S/PDIF sample rate on Archos/Sim yet */ /* Can't measure S/PDIF sample rate on Archos/Sim yet */
strncpy(buffer, "--", sizeof(buffer)); strlcpy(buffer, "--", sizeof(buffer));
} }
else else
#endif /* HAVE_SPDIF_IN */ #endif /* HAVE_SPDIF_IN */
{ {
static char const * const freq_strings[12] = static char const * const freq_strings[12] =
{ "44", "48", "32", "22", "24", "16" }; { "44", "48", "32", "22", "24", "16" };
strncpy(buffer, freq_strings[global_settings.rec_frequency], strlcpy(buffer, freq_strings[global_settings.rec_frequency],
sizeof(buffer)); sizeof(buffer));
} }

View file

@ -1489,8 +1489,7 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr)
break; break;
} }
strncpy(stringbuf, string_start, len); strlcpy(stringbuf, string_start, len+1);
*(stringbuf + len) = '\0';
data->strings[data->num_strings] = stringbuf; data->strings[data->num_strings] = stringbuf;
stringbuf += len + 1; stringbuf += len + 1;
@ -1781,11 +1780,9 @@ bool wps_data_load(struct wps_data *wps_data,
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
/* get the bitmap dir */ /* get the bitmap dir */
char bmpdir[MAX_PATH]; char bmpdir[MAX_PATH];
size_t bmpdirlen;
char *dot = strrchr(buf, '.'); char *dot = strrchr(buf, '.');
bmpdirlen = dot - buf;
strncpy(bmpdir, buf, dot - buf); strlcpy(bmpdir, buf, dot - buf + 1);
bmpdir[bmpdirlen] = 0;
/* load the bitmaps that were found by the parsing */ /* load the bitmaps that were found by the parsing */
if (!load_wps_bitmaps(wps_data, bmpdir)) { if (!load_wps_bitmaps(wps_data, bmpdir)) {

View file

@ -495,6 +495,7 @@ void iap_handlepkt(void)
unsigned char data[70] = {0x04, 0x00, 0xFF}; unsigned char data[70] = {0x04, 0x00, 0xFF};
struct mp3entry id3; struct mp3entry id3;
int fd; int fd;
size_t len;
long tracknum = (signed long)serbuf[4] << 24 | long tracknum = (signed long)serbuf[4] << 24 |
(signed long)serbuf[5] << 16 | (signed long)serbuf[5] << 16 |
(signed long)serbuf[6] << 8 | serbuf[7]; (signed long)serbuf[6] << 8 | serbuf[7];
@ -520,16 +521,16 @@ void iap_handlepkt(void)
switch(serbuf[3]) switch(serbuf[3])
{ {
case 0x20: case 0x20:
strncpy((char *)&data[3], id3.title, 64); len = strlcpy((char *)&data[3], id3.title, 64);
iap_send_pkt(data, 4+strlen(id3.title)); iap_send_pkt(data, 4+len);
break; break;
case 0x22: case 0x22:
strncpy((char *)&data[3], id3.artist, 64); len = strlcpy((char *)&data[3], id3.artist, 64);
iap_send_pkt(data, 4+strlen(id3.artist)); iap_send_pkt(data, 4+len);
break; break;
case 0x24: case 0x24:
strncpy((char *)&data[3], id3.album, 64); len = strlcpy((char *)&data[3], id3.album, 64);
iap_send_pkt(data, 4+strlen(id3.album)); iap_send_pkt(data, 4+len);
break; break;
} }
break; break;

View file

@ -321,7 +321,7 @@ void do_setting_from_menu(const struct menu_item_ex *temp,
while (i < MAX_PATH-1) while (i < MAX_PATH-1)
{ {
int padlen = MIN(len, MAX_PATH-1-i); int padlen = MIN(len, MAX_PATH-1-i);
strncpy(&padded_title[i], title, padlen); strlcpy(&padded_title[i], title, padlen);
i += padlen; i += padlen;
if (i<MAX_PATH-1) if (i<MAX_PATH-1)
padded_title[i++] = ' '; padded_title[i++] = ' ';

View file

@ -425,7 +425,7 @@ static void sleep_timer_formatter(char* buffer, size_t buffer_size, int value,
minutes = value - (hours * 60); minutes = value - (hours * 60);
snprintf(buffer, buffer_size, "%d:%02d", hours, minutes); snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
} else { } else {
strncpy(buffer, str(LANG_OFF), buffer_size); strlcpy(buffer, str(LANG_OFF), buffer_size);
} }
} }

View file

@ -403,7 +403,7 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname)
#endif #endif
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
strncpy(id3->path, trackname, sizeof(id3->path)); strlcpy(id3->path, trackname, sizeof(id3->path));
return true; return true;
} }

View file

@ -320,10 +320,9 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
if (len > 0) if (len > 0)
{ {
strncpy(buf, value, len);
buf[len] = 0;
*p = buf;
len++; len++;
strlcpy(buf, value, len);
*p = buf;
} }
else else
{ {

View file

@ -309,8 +309,7 @@ static int parseuser( struct mp3entry* entry, char* tag, int bufferpos )
value_len = bufferpos - (tag - entry->id3v2buf); value_len = bufferpos - (tag - entry->id3v2buf);
if (!strcasecmp(tag, "ALBUM ARTIST")) { if (!strcasecmp(tag, "ALBUM ARTIST")) {
strncpy(tag, value, value_len); strlcpy(tag, value, value_len);
tag[value_len - 1] = 0;
entry->albumartist = tag; entry->albumartist = tag;
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
} else { } else {
@ -1114,7 +1113,7 @@ bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename)
memset(entry, 0, sizeof(struct mp3entry)); memset(entry, 0, sizeof(struct mp3entry));
#endif #endif
strncpy(entry->path, filename, sizeof(entry->path)); strlcpy(entry->path, filename, sizeof(entry->path));
entry->title = NULL; entry->title = NULL;
entry->filesize = filesize(fd); entry->filesize = filesize(fd);

View file

@ -814,15 +814,13 @@ char *strip_extension(char* buffer, int buffer_size, const char *filename)
{ {
len = dot - filename; len = dot - filename;
len = MIN(len, buffer_size); len = MIN(len, buffer_size);
strncpy(buffer, filename, len);
} }
else else
{ {
len = buffer_size; len = buffer_size;
strncpy(buffer, filename, buffer_size);
} }
buffer[len] = 0; strlcpy(buffer, filename, len + 1);
return buffer; return buffer;
} }

View file

@ -2203,8 +2203,7 @@ void audio_record(const char *filename)
{ {
mpeg_errno = 0; mpeg_errno = 0;
strncpy(recording_filename, filename, MAX_PATH - 1); strlcpy(recording_filename, filename, MAX_PATH);
recording_filename[MAX_PATH - 1] = 0;
queue_post(&mpeg_queue, MPEG_RECORD, 0); queue_post(&mpeg_queue, MPEG_RECORD, 0);
} }
@ -2509,8 +2508,7 @@ void audio_new_file(const char *filename)
{ {
mpeg_errno = 0; mpeg_errno = 0;
strncpy(recording_filename, filename, MAX_PATH - 1); strlcpy(recording_filename, filename, MAX_PATH);
recording_filename[MAX_PATH - 1] = 0;
queue_post(&mpeg_queue, MPEG_NEW_FILE, 0); queue_post(&mpeg_queue, MPEG_NEW_FILE, 0);
} }

View file

@ -532,7 +532,7 @@ static bool delete_handler(bool is_dir)
{ {
char pathname[MAX_PATH]; /* space to go deep */ char pathname[MAX_PATH]; /* space to go deep */
cpu_boost(true); cpu_boost(true);
strncpy(pathname, file_to_delete, sizeof pathname); strlcpy(pathname, file_to_delete, sizeof(pathname));
res = remove_dir(pathname, sizeof(pathname)); res = remove_dir(pathname, sizeof(pathname));
cpu_boost(false); cpu_boost(false);
} }
@ -578,7 +578,7 @@ static bool rename_file(void)
char newname[MAX_PATH]; char newname[MAX_PATH];
char* ptr = strrchr(selected_file, '/') + 1; char* ptr = strrchr(selected_file, '/') + 1;
int pathlen = (ptr - selected_file); int pathlen = (ptr - selected_file);
strncpy(newname, selected_file, sizeof newname); strlcpy(newname, selected_file, sizeof(newname));
if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) { if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
if (!strlen(newname + pathlen) || if (!strlen(newname + pathlen) ||
(rename(selected_file, newname) < 0)) { (rename(selected_file, newname) < 0)) {
@ -638,7 +638,7 @@ static bool properties(void)
static bool clipboard_clip(bool copy) static bool clipboard_clip(bool copy)
{ {
clipboard_selection[0] = 0; clipboard_selection[0] = 0;
strncpy(clipboard_selection, selected_file, sizeof(clipboard_selection)); strlcpy(clipboard_selection, selected_file, sizeof(clipboard_selection));
clipboard_selection_attr = selected_file_attr; clipboard_selection_attr = selected_file_attr;
clipboard_is_copy = copy; clipboard_is_copy = copy;
@ -895,15 +895,15 @@ static bool clipboard_paste(void)
} }
else else
{ {
strncpy(srcpath, clipboard_selection, sizeof(srcpath)); strlcpy(srcpath, clipboard_selection, sizeof(srcpath));
strncpy(targetpath, target, sizeof(targetpath)); strlcpy(targetpath, target, sizeof(targetpath));
success = clipboard_pastedirectory(srcpath, sizeof(srcpath), success = clipboard_pastedirectory(srcpath, sizeof(srcpath),
target, sizeof(targetpath), clipboard_is_copy); target, sizeof(targetpath), clipboard_is_copy);
if (success && !clipboard_is_copy) if (success && !clipboard_is_copy)
{ {
strncpy(srcpath, clipboard_selection, sizeof(srcpath)); strlcpy(srcpath, clipboard_selection, sizeof(srcpath));
remove_dir(srcpath, sizeof(srcpath)); remove_dir(srcpath, sizeof(srcpath));
} }
} }
@ -1026,7 +1026,7 @@ MENUITEM_FUNCTION(set_backdrop_item, 0, ID2P(LANG_SET_AS_BACKDROP),
#ifdef HAVE_RECORDING #ifdef HAVE_RECORDING
static bool set_recdir(void) static bool set_recdir(void)
{ {
strncpy(global_settings.rec_directory, strlcpy(global_settings.rec_directory,
selected_file, MAX_FILENAME+1); selected_file, MAX_FILENAME+1);
settings_save(); settings_save();
return false; return false;

View file

@ -617,7 +617,7 @@ struct mp3entry* audio_current_track(void)
return write_id3; return write_id3;
#endif #endif
strncpy(write_id3->path, filename, sizeof(write_id3->path)-1); strlcpy(write_id3->path, filename, sizeof(write_id3->path));
write_id3->title = strrchr(write_id3->path, '/'); write_id3->title = strrchr(write_id3->path, '/');
if (!write_id3->title) if (!write_id3->title)
write_id3->title = &write_id3->path[0]; write_id3->title = &write_id3->path[0];

View file

@ -1349,8 +1349,7 @@ static int get_filename(struct playlist_info* playlist, int index, int seek,
if (playlist->in_ram && !control_file && max < 0) if (playlist->in_ram && !control_file && max < 0)
{ {
strncpy(tmp_buf, &playlist->buffer[seek], sizeof(tmp_buf)); strlcpy(tmp_buf, &playlist->buffer[seek], sizeof(tmp_buf));
tmp_buf[MAX_PATH] = '\0';
max = strlen(tmp_buf) + 1; max = strlen(tmp_buf) + 1;
} }
else if (max < 0) else if (max < 0)
@ -1402,8 +1401,7 @@ static int get_filename(struct playlist_info* playlist, int index, int seek,
} }
} }
strncpy(dir_buf, playlist->filename, playlist->dirlen-1); strlcpy(dir_buf, playlist->filename, playlist->dirlen);
dir_buf[playlist->dirlen-1] = 0;
return (format_track_path(buf, tmp_buf, buf_length, max, dir_buf)); return (format_track_path(buf, tmp_buf, buf_length, max, dir_buf));
} }
@ -1471,8 +1469,7 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
else else
{ {
/* start with current directory */ /* start with current directory */
strncpy(dir, playlist->filename, playlist->dirlen-1); strlcpy(dir, playlist->filename, playlist->dirlen);
dir[playlist->dirlen-1] = '\0';
} }
/* use the tree browser dircache to load files */ /* use the tree browser dircache to load files */
@ -1671,13 +1668,13 @@ static int format_track_path(char *dest, char *src, int buf_length, int max,
if('/' == src[0]) if('/' == src[0])
{ {
strncpy(dest, src, buf_length); strlcpy(dest, src, buf_length);
} }
else else
{ {
/* handle dos style drive letter */ /* handle dos style drive letter */
if (':' == src[1]) if (':' == src[1])
strncpy(dest, &src[2], buf_length); strlcpy(dest, &src[2], buf_length);
else if (!strncmp(src, "../", 3)) else if (!strncmp(src, "../", 3))
{ {
/* handle relative paths */ /* handle relative paths */
@ -1904,7 +1901,7 @@ void playlist_init(void)
struct playlist_info* playlist = &current_playlist; struct playlist_info* playlist = &current_playlist;
playlist->current = true; playlist->current = true;
strncpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, strlcpy(playlist->control_filename, PLAYLIST_CONTROL_FILE,
sizeof(playlist->control_filename)); sizeof(playlist->control_filename));
playlist->fd = -1; playlist->fd = -1;
playlist->control_fd = -1; playlist->control_fd = -1;
@ -2721,7 +2718,7 @@ int playlist_set_current(struct playlist_info* playlist)
empty_playlist(&current_playlist, false); empty_playlist(&current_playlist, false);
strncpy(current_playlist.filename, playlist->filename, strlcpy(current_playlist.filename, playlist->filename,
sizeof(current_playlist.filename)); sizeof(current_playlist.filename));
current_playlist.utf8 = playlist->utf8; current_playlist.utf8 = playlist->utf8;
@ -3240,7 +3237,7 @@ char *playlist_name(const struct playlist_info* playlist, char *buf,
if (!playlist) if (!playlist)
playlist = &current_playlist; playlist = &current_playlist;
strncpy(buf, playlist->filename+playlist->dirlen, buf_size); strlcpy(buf, playlist->filename+playlist->dirlen, buf_size);
if (!buf[0]) if (!buf[0])
return NULL; return NULL;
@ -3260,7 +3257,7 @@ char *playlist_get_name(const struct playlist_info* playlist, char *buf,
if (!playlist) if (!playlist)
playlist = &current_playlist; playlist = &current_playlist;
strncpy(buf, playlist->filename, buf_size); strlcpy(buf, playlist->filename, buf_size);
if (!buf[0]) if (!buf[0])
return NULL; return NULL;

View file

@ -78,7 +78,7 @@ static int initialize_catalog(void)
/* fall back to default directory if no or invalid config */ /* fall back to default directory if no or invalid config */
if (default_dir) if (default_dir)
strncpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR, strlcpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR,
sizeof(playlist_dir)); sizeof(playlist_dir));
playlist_dir_length = strlen(playlist_dir); playlist_dir_length = strlen(playlist_dir);
@ -189,7 +189,7 @@ static char* playlist_callback_name(int selected_item, void* data,
{ {
char** playlists = (char**) data; char** playlists = (char**) data;
strncpy(buffer, playlists[selected_item], buffer_len); strlcpy(buffer, playlists[selected_item], buffer_len);
if (buffer[0] != '.' && !(global_settings.show_filename_ext == 1 if (buffer[0] != '.' && !(global_settings.show_filename_ext == 1
|| (global_settings.show_filename_ext == 3 || (global_settings.show_filename_ext == 3
@ -478,7 +478,7 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
if (add_to_playlist(playlist, new_playlist, sel, sel_attr) == 0) if (add_to_playlist(playlist, new_playlist, sel, sel_attr) == 0)
{ {
strncpy(most_recent_playlist, playlist+playlist_dir_length+1, strlcpy(most_recent_playlist, playlist+playlist_dir_length+1,
sizeof(most_recent_playlist)); sizeof(most_recent_playlist));
return true; return true;
} }

View file

@ -381,7 +381,7 @@ static const struct plugin_api rockbox_api = {
snprintf, snprintf,
vsnprintf, vsnprintf,
strcpy, strcpy,
strncpy, strlcpy,
strlen, strlen,
strrchr, strrchr,
strcmp, strcmp,

View file

@ -38,6 +38,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
char* strncpy(char *, const char *, size_t);
void* plugin_get_buffer(size_t *buffer_size); void* plugin_get_buffer(size_t *buffer_size);
#ifndef __PCTOOL__ #ifndef __PCTOOL__
@ -128,12 +129,12 @@ void* plugin_get_buffer(size_t *buffer_size);
#define PLUGIN_MAGIC 0x526F634B /* RocK */ #define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */ /* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 160 #define PLUGIN_API_VERSION 161
/* update this to latest version if a change to the api struct breaks /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 160 #define PLUGIN_MIN_API_VERSION 161
/* plugin return codes */ /* plugin return codes */
enum plugin_status { enum plugin_status {
@ -505,7 +506,7 @@ struct plugin_api {
ATTRIBUTE_PRINTF(3, 4); ATTRIBUTE_PRINTF(3, 4);
int (*vsnprintf)(char *buf, int size, const char *fmt, va_list ap); int (*vsnprintf)(char *buf, int size, const char *fmt, va_list ap);
char* (*strcpy)(char *dst, const char *src); char* (*strcpy)(char *dst, const char *src);
char* (*strncpy)(char *dst, const char *src, size_t length); size_t (*strlcpy)(char *dst, const char *src, size_t length);
size_t (*strlen)(const char *str); size_t (*strlen)(const char *str);
char * (*strrchr)(const char *s, int c); char * (*strrchr)(const char *s, int c);
int (*strcmp)(const char *, const char *); int (*strcmp)(const char *, const char *);

View file

@ -543,7 +543,7 @@ char * get_game_text(int selected_item, void *data,
rb->snprintf(text_buffer, 50,"%s vs. %s (%s)", temp_node->white_player, rb->snprintf(text_buffer, 50,"%s vs. %s (%s)", temp_node->white_player,
temp_node->black_player, temp_node->game_date); temp_node->black_player, temp_node->game_date);
rb->strncpy(buffer, text_buffer, buffer_len); rb->strlcpy(buffer, text_buffer, buffer_len);
return buffer; return buffer;
} }

View file

@ -283,8 +283,7 @@ enum plugin_status plugin_start(const void* parameter)
while (1) while (1)
{ {
/* copy one lcd line */ /* copy one lcd line */
rb->strncpy(output, ptr, display_columns); rb->strlcpy(output, ptr, display_columns + 1);
output[display_columns] = '\0';
/* typecast to kill a warning... */ /* typecast to kill a warning... */
if((int)rb->strlen(ptr) < display_columns) if((int)rb->strlen(ptr) < display_columns)

View file

@ -59,7 +59,6 @@ int my_close(int id);
#define memcmp(a,b,c) rb->memcmp((a),(b),(c)) #define memcmp(a,b,c) rb->memcmp((a),(b),(c))
#define memchr(a,b,c) rb->memchr((a),(b),(c)) #define memchr(a,b,c) rb->memchr((a),(b),(c))
#define strcpy(a,b) rb->strcpy((a),(b)) #define strcpy(a,b) rb->strcpy((a),(b))
#define strncpy(a,b,c) rb->strncpy((a),(b),(c))
#define strlen(a) rb->strlen((a)) #define strlen(a) rb->strlen((a))
#define strcmp(a,b) rb->strcmp((a),(b)) #define strcmp(a,b) rb->strcmp((a),(b))
#define strncmp(a,b,c) rb->strncmp((a),(b),(c)) #define strncmp(a,b,c) rb->strncmp((a),(b),(c))

View file

@ -130,7 +130,7 @@ output_header_props (void)
{ {
char buffer[128]; char buffer[128];
rb->strncpy (buffer, "GM[1]FF[4]CA[UTF-8]AP[Rockbox Goban:1.0]ST[2]\n\n", rb->strlcpy (buffer, "GM[1]FF[4]CA[UTF-8]AP[Rockbox Goban:1.0]ST[2]\n\n",
sizeof (buffer)); sizeof (buffer));
write_file (sgf_fd, buffer, rb->strlen (buffer)); write_file (sgf_fd, buffer, rb->strlen (buffer));

View file

@ -1511,7 +1511,7 @@ void init_invadrox(void)
if (highscore_load(HISCOREFILE, &hiscore, 1) < 0) { if (highscore_load(HISCOREFILE, &hiscore, 1) < 0) {
/* Init hiscore to 0 */ /* Init hiscore to 0 */
rb->strncpy(hiscore.name, "Invader", sizeof(hiscore.name)); rb->strlcpy(hiscore.name, "Invader", sizeof(hiscore.name));
hiscore.score = 0; hiscore.score = 0;
hiscore.level = 1; hiscore.level = 1;
} }

View file

@ -330,11 +330,11 @@ static void hash_pw(union hash *out)
static void make_key(void) static void make_key(void)
{ {
int i; int i;
char buf[sizeof(master_pw) + sizeof(salt) + 1]; char buf[sizeof(master_pw) + sizeof(salt) + 1] = {0};
struct md5_s key_md5; struct md5_s key_md5;
size_t len = rb->strlen(master_pw); size_t len = rb->strlen(master_pw);
rb->strncpy(buf, master_pw, sizeof(buf)); rb->strlcpy(buf, master_pw, sizeof(buf));
rb->memcpy(&buf[len], &salt, sizeof(salt)); rb->memcpy(&buf[len], &salt, sizeof(salt));
@ -418,7 +418,7 @@ static int parse_buffer(void)
break; break;
} }
rb->strncpy(entry->title, start, FIELD_LEN); rb->strlcpy(entry->title, start, FIELD_LEN);
start = end + 1; start = end + 1;
end = rb->strchr(start, '\0'); /* find eol */ end = rb->strchr(start, '\0'); /* find eol */
@ -428,7 +428,7 @@ static int parse_buffer(void)
break; break;
} }
rb->strncpy(entry->name, start, FIELD_LEN); rb->strlcpy(entry->name, start, FIELD_LEN);
start = end + 1; start = end + 1;
end = rb->strchr(start, '\0'); /* find eol */ end = rb->strchr(start, '\0'); /* find eol */
@ -437,7 +437,7 @@ static int parse_buffer(void)
{ {
break; break;
} }
rb->strncpy(entry->password, start, FIELD_LEN); rb->strlcpy(entry->password, start, FIELD_LEN);
start = end + 1; start = end + 1;
entry->used = true; entry->used = true;
if (i + 1 < MAX_ENTRIES - 1) if (i + 1 < MAX_ENTRIES - 1)
@ -469,13 +469,13 @@ static void write_output(int fd)
for (i = 0; i < pw_list.num_entries; i++) for (i = 0; i < pw_list.num_entries; i++)
{ {
len = rb->strlen(entry->title); len = rb->strlen(entry->title);
rb->strncpy(p, entry->title, len+1); rb->strlcpy(p, entry->title, len+1);
p += len+1; p += len+1;
len = rb->strlen(entry->name); len = rb->strlen(entry->name);
rb->strncpy(p, entry->name, len+1); rb->strlcpy(p, entry->name, len+1);
p += len+1; p += len+1;
len = rb->strlen(entry->password); len = rb->strlen(entry->password);
rb->strncpy(p, entry->password, len+1); rb->strlcpy(p, entry->password, len+1);
p += len+1; p += len+1;
if (entry->next) if (entry->next)
entry = entry->next; entry = entry->next;
@ -517,7 +517,7 @@ static int enter_pw(char *pw_buf, size_t buflen, bool new_pw)
} }
else else
{ {
rb->strncpy(pw_buf, buf[0], buflen); rb->strlcpy(pw_buf, buf[0], buflen);
hash_pw(&pwhash); hash_pw(&pwhash);
return 0; return 0;
} }

View file

@ -6,6 +6,7 @@ playback_control.c
rgb_hsv.c rgb_hsv.c
buflib.c buflib.c
display_text.c display_text.c
strncpy.c
#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
grey_core.c grey_core.c
grey_draw.c grey_draw.c

View file

@ -139,7 +139,7 @@ int configfile_load(const char *filename, struct configdata *cfg,
break; break;
case TYPE_STRING: case TYPE_STRING:
rb->strncpy(cfg[i].string, val, cfg[i].max); rb->strlcpy(cfg[i].string, val, cfg[i].max);
break; break;
} }
} }

View file

@ -72,7 +72,7 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores)
scores[i].score = rb->atoi(score); scores[i].score = rb->atoi(score);
scores[i].level = rb->atoi(level); scores[i].level = rb->atoi(level);
rb->strncpy(scores[i].name, name, sizeof(scores[i].name)-1); rb->strlcpy(scores[i].name, name, sizeof(scores[i].name));
i++; i++;
} }
rb->close(fd); rb->close(fd);
@ -100,8 +100,7 @@ int highscore_update(int score, int level, const char *name,
entry = scores + pos; entry = scores + pos;
entry->score = score; entry->score = score;
entry->level = level; entry->level = level;
rb->strncpy(entry->name, name, sizeof(entry->name)); rb->strlcpy(entry->name, name, sizeof(entry->name));
entry->name[sizeof(entry->name)-1] = '\0';
return pos; return pos;
} }

View file

@ -51,7 +51,7 @@
#define strcpy rb->strcpy #define strcpy rb->strcpy
#define strip_extension rb->strip_extension #define strip_extension rb->strip_extension
#define strlen rb->strlen #define strlen rb->strlen
#define strncpy rb->strncpy #define strlcpy rb->strlcpy
#define strrchr rb->strrchr #define strrchr rb->strrchr
#endif #endif

View file

@ -181,8 +181,7 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
void luaO_chunkid (char *out, const char *source, size_t bufflen) { void luaO_chunkid (char *out, const char *source, size_t bufflen) {
if (*source == '=') { if (*source == '=') {
strncpy(out, source+1, bufflen); /* remove first char */ strlcpy(out, source+1, bufflen); /* remove first char */
out[bufflen-1] = '\0'; /* ensures null termination */
} }
else { /* out = "source", or "...source" */ else { /* out = "source", or "...source" */
if (*source == '@') { if (*source == '@') {

View file

@ -737,9 +737,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
if (isdigit(uchar(*p))) if (isdigit(uchar(*p)))
luaL_error(L, "invalid format (width or precision too long)"); luaL_error(L, "invalid format (width or precision too long)");
*(form++) = '%'; *(form++) = '%';
strncpy(form, strfrmt, p - strfrmt + 1); strlcpy(form, strfrmt, p - strfrmt + 1);
form += p - strfrmt + 1;
*form = '\0';
return p; return p;
} }

View file

@ -63,7 +63,7 @@ long pow(long x, long y);
#define strchr rb->strchr #define strchr rb->strchr
#define strcmp rb->strcmp #define strcmp rb->strcmp
#define strcpy rb->strcpy #define strcpy rb->strcpy
#define strncpy rb->strncpy #define strlcpy rb->strlcpy
#define strlen rb->strlen #define strlen rb->strlen
#endif /* _ROCKCONF_H_ */ #endif /* _ROCKCONF_H_ */

View file

@ -2399,9 +2399,8 @@ char mp3_name[80];
void get_mp3_filename(const char *wav_name) void get_mp3_filename(const char *wav_name)
{ {
int slen = rb->strlen(wav_name); rb->strlcpy(mp3_name, wav_name, sizeof(mp3_name));
rb->strncpy(mp3_name, wav_name, 79); rb->strlcpy(mp3_name + rb->strlen(mp3_name) - 4, ".mp3", 5);
rb->strncpy(mp3_name + slen - 4, ".mp3", 5);
} }
#if CONFIG_KEYPAD == IRIVER_H100_PAD || CONFIG_KEYPAD == IRIVER_H300_PAD #if CONFIG_KEYPAD == IRIVER_H100_PAD || CONFIG_KEYPAD == IRIVER_H300_PAD

View file

@ -344,7 +344,7 @@ static void backlight_brightness_formatter(char *buf, size_t length,
int value, const char *input) int value, const char *input)
{ {
if (value < 0) if (value < 0)
rb->strncpy(buf, BACKLIGHT_OPTION_DEFAULT, length); rb->strlcpy(buf, BACKLIGHT_OPTION_DEFAULT, length);
else else
rb->snprintf(buf, length, "%d", value + MIN_BRIGHTNESS_SETTING); rb->snprintf(buf, length, "%d", value + MIN_BRIGHTNESS_SETTING);

View file

@ -913,7 +913,7 @@ bool get_albumart_for_index_from_db(const int slide_index, char *buf,
{ {
if ( slide_index == -1 ) if ( slide_index == -1 )
{ {
rb->strncpy( buf, EMPTY_SLIDE, buflen ); rb->strlcpy( buf, EMPTY_SLIDE, buflen );
} }
if (!rb->tagcache_search(&tcs, tag_filename)) if (!rb->tagcache_search(&tcs, tag_filename))
@ -930,8 +930,7 @@ bool get_albumart_for_index_from_db(const int slide_index, char *buf,
#ifdef HAVE_TC_RAMCACHE #ifdef HAVE_TC_RAMCACHE
if (rb->tagcache_fill_tags(&id3, tcs.result)) if (rb->tagcache_fill_tags(&id3, tcs.result))
{ {
rb->strncpy(id3.path, tcs.result, sizeof(id3.path)); rb->strlcpy(id3.path, tcs.result, sizeof(id3.path));
id3.path[sizeof(id3.path) - 1] = 0;
} }
else else
#endif #endif

View file

@ -70,8 +70,7 @@ static bool file_properties(char* selected_file)
char* ptr = rb->strrchr(selected_file, '/') + 1; char* ptr = rb->strrchr(selected_file, '/') + 1;
int dirlen = (ptr - selected_file); int dirlen = (ptr - selected_file);
rb->strncpy(tstr, selected_file, dirlen); rb->strlcpy(tstr, selected_file, dirlen + 1);
tstr[dirlen] = 0;
dir = rb->opendir(tstr); dir = rb->opendir(tstr);
if (dir) if (dir)
@ -212,7 +211,7 @@ static bool dir_properties(char* selected_file)
{ {
DPS dps; DPS dps;
char tstr[64]; char tstr[64];
rb->strncpy(dps.dirname, selected_file, MAX_PATH); rb->strlcpy(dps.dirname, selected_file, MAX_PATH);
dps.len = MAX_PATH; dps.len = MAX_PATH;
dps.dc = 0; dps.dc = 0;
dps.fc = 0; dps.fc = 0;
@ -220,7 +219,7 @@ static bool dir_properties(char* selected_file)
if(false == _dir_properties(&dps)) if(false == _dir_properties(&dps))
return false; return false;
rb->strncpy(str_dirname, selected_file, MAX_PATH); rb->strlcpy(str_dirname, selected_file, MAX_PATH);
rb->snprintf(str_dircount, sizeof str_dircount, "Subdirs: %d", dps.dc); rb->snprintf(str_dircount, sizeof str_dircount, "Subdirs: %d", dps.dc);
rb->snprintf(str_filecount, sizeof str_filecount, "Files: %d", dps.fc); rb->snprintf(str_filecount, sizeof str_filecount, "Files: %d", dps.fc);
rb->snprintf(str_size, sizeof str_size, "Size: %s", rb->snprintf(str_size, sizeof str_size, "Size: %s",
@ -236,35 +235,35 @@ char * get_props(int selected_item, void* data, char *buffer, size_t buffer_len)
switch(selected_item) switch(selected_item)
{ {
case 0: case 0:
rb->strncpy(buffer, str_dirname, buffer_len); rb->strlcpy(buffer, str_dirname, buffer_len);
break; break;
case 1: case 1:
rb->strncpy(buffer, its_a_dir ? str_dircount : str_filename, rb->strlcpy(buffer, its_a_dir ? str_dircount : str_filename,
buffer_len); buffer_len);
break; break;
case 2: case 2:
rb->strncpy(buffer, its_a_dir ? str_filecount : str_size, buffer_len); rb->strlcpy(buffer, its_a_dir ? str_filecount : str_size, buffer_len);
break; break;
case 3: case 3:
rb->strncpy(buffer, its_a_dir ? str_size : str_date, buffer_len); rb->strlcpy(buffer, its_a_dir ? str_size : str_date, buffer_len);
break; break;
case 4: case 4:
rb->strncpy(buffer, its_a_dir ? "" : str_time, buffer_len); rb->strlcpy(buffer, its_a_dir ? "" : str_time, buffer_len);
break; break;
case 5: case 5:
rb->strncpy(buffer, its_a_dir ? "" : str_artist, buffer_len); rb->strlcpy(buffer, its_a_dir ? "" : str_artist, buffer_len);
break; break;
case 6: case 6:
rb->strncpy(buffer, its_a_dir ? "" : str_title, buffer_len); rb->strlcpy(buffer, its_a_dir ? "" : str_title, buffer_len);
break; break;
case 7: case 7:
rb->strncpy(buffer, its_a_dir ? "" : str_album, buffer_len); rb->strlcpy(buffer, its_a_dir ? "" : str_album, buffer_len);
break; break;
case 8: case 8:
rb->strncpy(buffer, its_a_dir ? "" : str_duration, buffer_len); rb->strlcpy(buffer, its_a_dir ? "" : str_duration, buffer_len);
break; break;
default: default:
rb->strncpy(buffer, "ERROR", buffer_len); rb->strlcpy(buffer, "ERROR", buffer_len);
break; break;
} }
return buffer; return buffer;
@ -284,8 +283,7 @@ enum plugin_status plugin_start(const void* parameter)
struct dirent* entry; struct dirent* entry;
char* ptr = rb->strrchr(file, '/') + 1; char* ptr = rb->strrchr(file, '/') + 1;
int dirlen = (ptr - file); int dirlen = (ptr - file);
rb->strncpy(str_dirname, file, dirlen); rb->strlcpy(str_dirname, file, dirlen + 1);
str_dirname[dirlen] = 0;
dir = rb->opendir(str_dirname); dir = rb->opendir(str_dirname);
if (dir) if (dir)

View file

@ -86,7 +86,7 @@ void traversedir(char* location, char* name)
/* check if path is removed directory, if so dont enter it */ /* check if path is removed directory, if so dont enter it */
rb->snprintf(path, MAX_PATH, "%s/%s", fullpath, entry->d_name); rb->snprintf(path, MAX_PATH, "%s/%s", fullpath, entry->d_name);
while(path[0] == '/') while(path[0] == '/')
rb->strncpy(path, path + 1, rb->strlen(path)); rb->strlcpy(path, path + 1, sizeof(path));
for(i = 0; i < num_replaced_dirs; i++) for(i = 0; i < num_replaced_dirs; i++)
{ {
if(!rb->strcmp(path, removed_dirs[i])) if(!rb->strcmp(path, removed_dirs[i]))
@ -141,8 +141,8 @@ bool custom_dir(void)
(num_replaced_dirs < MAX_REMOVED_DIRS)) (num_replaced_dirs < MAX_REMOVED_DIRS))
{ {
num_replaced_dirs ++; num_replaced_dirs ++;
rb->strncpy(removed_dirs[num_replaced_dirs - 1], line + 2, rb->strlcpy(removed_dirs[num_replaced_dirs - 1], line + 2,
rb->strlen(line)); sizeof(line));
} }
} }
rb->close(fd2); rb->close(fd2);
@ -157,7 +157,7 @@ bool custom_dir(void)
{ {
/* remove preceeding '/'s from the line */ /* remove preceeding '/'s from the line */
while(line[0] == '/') while(line[0] == '/')
rb->strncpy(line, line + 1, rb->strlen(line)); rb->strlcpy(line, line + 1, sizeof(line));
rb->snprintf(formatted_line, MAX_PATH, "/%s", line); rb->snprintf(formatted_line, MAX_PATH, "/%s", line);
@ -237,7 +237,7 @@ void generate(void)
char *list_get_name_cb(int selected_item, void* data, char* buf, size_t buf_len) char *list_get_name_cb(int selected_item, void* data, char* buf, size_t buf_len)
{ {
(void)data; (void)data;
rb->strncpy(buf, list->folder[selected_item], buf_len); rb->strlcpy(buf, list->folder[selected_item], buf_len);
return buf; return buf;
} }

View file

@ -162,11 +162,10 @@ static void munge_name(char *buf, const size_t bufsiz) {
* checksum or something like that? * checksum or something like that?
*/ */
static void build_slot_path(char *buf, size_t bufsiz, size_t slot_id) { static void build_slot_path(char *buf, size_t bufsiz, size_t slot_id) {
char name_buf[40]; char name_buf[17];
/* munge state file name */ /* munge state file name */
strncpy(name_buf, rom.name, 40); strlcpy(name_buf, rom.name, sizeof(name_buf));
name_buf[16] = '\0';
munge_name(name_buf, strlen(name_buf)); munge_name(name_buf, strlen(name_buf));
/* glom the whole mess together */ /* glom the whole mess together */
@ -211,7 +210,7 @@ static bool do_file(char *path, char *desc, bool is_load) {
/* build description buffer */ /* build description buffer */
memset(desc_buf, 0, 20); memset(desc_buf, 0, 20);
if (desc) if (desc)
strncpy(desc_buf, desc, 20); strlcpy(desc_buf, desc, 20);
/* save state */ /* save state */
write(fd, desc_buf, 20); write(fd, desc_buf, 20);
@ -241,8 +240,7 @@ static bool do_slot(size_t slot_id, bool is_load) {
if (!is_load) if (!is_load)
if (rb->kbd_input(desc_buf, 20) || !strlen(desc_buf)) if (rb->kbd_input(desc_buf, 20) || !strlen(desc_buf))
{ {
memset(desc_buf, 0, 20); strlcpy(desc_buf, "Untitled", 20);
strncpy(desc_buf, "Untitled", 20);
} }
/* load/save file */ /* load/save file */

View file

@ -67,7 +67,7 @@ void dynamic_recompile (struct dynarec_block *newblock);
#define strcat(a,b) rb->strcat((a),(b)) #define strcat(a,b) rb->strcat((a),(b))
#define memset(a,b,c) rb->memset((a),(b),(c)) #define memset(a,b,c) rb->memset((a),(b),(c))
#define strcpy(a,b) rb->strcpy((a),(b)) #define strcpy(a,b) rb->strcpy((a),(b))
#define strncpy(a,b,c) rb->strncpy((a),(b),(c)) #define strlcpy(a,b,c) rb->strlcpy((a),(b),(c))
#define strlen(a) rb->strlen((a)) #define strlen(a) rb->strlen((a))
#define strcmp(a,b) rb->strcmp((a),(b)) #define strcmp(a,b) rb->strcmp((a),(b))
#define strchr(a,b) rb->strchr((a),(b)) #define strchr(a,b) rb->strchr((a),(b))

View file

@ -686,7 +686,7 @@ static bool browse( char *dst, int dst_size, const char *start )
if( selected < 0 || selected >= item_count ) if( selected < 0 || selected >= item_count )
break; break;
struct entry* e = &dc[indexes[selected]]; struct entry* e = &dc[indexes[selected]];
rb->strncpy( bbuf_s, e->name, sizeof( bbuf_s ) ); rb->strlcpy( bbuf_s, e->name, sizeof( bbuf_s ) );
if( !( e->attr & ATTR_DIRECTORY ) ) if( !( e->attr & ATTR_DIRECTORY ) )
{ {
*tree = backup; *tree = backup;

View file

@ -213,8 +213,7 @@ bool parse_entry_content(char *line, sc_entry_t *entry, int last_segm)
DEBUGF("Bad entry: pathlen=%d, displen=%d\n", path_len, disp_len); DEBUGF("Bad entry: pathlen=%d, displen=%d\n", path_len, disp_len);
return false; return false;
} }
rb->strncpy(entry->path, path, path_len); rb->strlcpy(entry->path, path, path_len + 1);
entry->path[path_len] = '\0';
rb->strcpy(entry->disp, disp); /* Safe since we've checked the length */ rb->strcpy(entry->disp, disp); /* Safe since we've checked the length */
entry->explicit_disp = expl; entry->explicit_disp = expl;
return true; return true;
@ -295,15 +294,14 @@ bool parse_name_value(char *line, char *name, int namesize,
/* Too long name */ /* Too long name */
return false; return false;
} }
rb->strncpy(name, line, name_len); rb->strlcpy(name, line, name_len + 1);
name[name_len] = '\0';
val_len = rb->strlen(line) - name_len - NAME_VALUE_SEPARATOR_LEN; val_len = rb->strlen(line) - name_len - NAME_VALUE_SEPARATOR_LEN;
if (val_len >= valuesize) { if (val_len >= valuesize) {
/* Too long value */ /* Too long value */
return false; return false;
} }
rb->strncpy(value, sep+NAME_VALUE_SEPARATOR_LEN, val_len+1); rb->strlcpy(value, sep+NAME_VALUE_SEPARATOR_LEN, val_len+1);
return true; return true;
} }

View file

@ -689,7 +689,8 @@ static bool redo(void)
static void init_boards(void) static void init_boards(void)
{ {
rb->strncpy(buffered_boards.filename, SOKOBAN_LEVELS_FILE, MAX_PATH); rb->strlcpy(buffered_boards.filename, SOKOBAN_LEVELS_FILE,
sizeof(buffered_boards.filename));
current_info.level.index = 0; current_info.level.index = 0;
current_info.player.row = 0; current_info.player.row = 0;
@ -1026,8 +1027,8 @@ static bool save(char *filename, bool solution)
/* Create dir if it doesn't exist */ /* Create dir if it doesn't exist */
if ((loc = rb->strrchr(filename, '/')) != NULL) { if ((loc = rb->strrchr(filename, '/')) != NULL) {
rb->strncpy(dirname, filename, loc - filename); rb->strlcpy(dirname, filename, loc - filename + 1);
dirname[loc - filename] = '\0';
if(!(dir = rb->opendir(dirname))) if(!(dir = rb->opendir(dirname)))
rb->mkdir(dirname); rb->mkdir(dirname);
else else
@ -1082,7 +1083,9 @@ static bool load(char *filename, bool silent)
if (rb->strncmp(buf, "Sokoban", 7) != 0) { if (rb->strncmp(buf, "Sokoban", 7) != 0) {
rb->close(fd); rb->close(fd);
rb->strncpy(buffered_boards.filename, filename, MAX_PATH); rb->strlcpy(buffered_boards.filename, filename,
sizeof(buffered_boards.filename));
if (!read_levels(true)) if (!read_levels(true))
return false; return false;

View file

@ -780,11 +780,11 @@ static void save_editor(struct mp3entry *mp3, int splittime)
bool part2_save = true; bool part2_save = true;
/* file name for left part */ /* file name for left part */
rb->strncpy(part1_name, mp3->path, MAX_PATH); rb->strlcpy(part1_name, mp3->path, MAX_PATH);
generateFileName(part1_name, 1); generateFileName(part1_name, 1);
/* file name for right part */ /* file name for right part */
rb->strncpy(part2_name, mp3->path, MAX_PATH); rb->strlcpy(part2_name, mp3->path, MAX_PATH);
generateFileName(part2_name, 2); generateFileName(part2_name, 2);
while (!exit_request) while (!exit_request)

View file

@ -603,7 +603,7 @@ void default_state(struct sudoku_state_t* state)
{ {
int r,c; int r,c;
rb->strncpy(state->filename,GAME_FILE,MAX_PATH); rb->strlcpy(state->filename,GAME_FILE,MAX_PATH);
for (r=0;r<9;r++) { for (r=0;r<9;r++) {
for (c=0;c<9;c++) { for (c=0;c<9;c++) {
state->startboard[r][c]=default_game[r][c]; state->startboard[r][c]=default_game[r][c];
@ -626,7 +626,7 @@ void clear_state(struct sudoku_state_t* state)
{ {
int r,c; int r,c;
rb->strncpy(state->filename,GAME_FILE,MAX_PATH); rb->strlcpy(state->filename,GAME_FILE,MAX_PATH);
for (r=0;r<9;r++) { for (r=0;r<9;r++) {
for (c=0;c<9;c++) { for (c=0;c<9;c++) {
state->startboard[r][c]='0'; state->startboard[r][c]='0';
@ -719,7 +719,7 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
return(false); return(false);
} }
rb->strncpy(state->filename,filename,MAX_PATH); rb->strlcpy(state->filename,filename,MAX_PATH);
n=rb->read(fd,buf,300); n=rb->read(fd,buf,300);
if (n <= 0) { if (n <= 0) {
return(false); return(false);
@ -1111,7 +1111,7 @@ bool sudoku_generate(struct sudoku_state_t* state)
rb->snprintf(str,sizeof(str),"Difficulty: %s",difficulty); rb->snprintf(str,sizeof(str),"Difficulty: %s",difficulty);
display_board(state); display_board(state);
rb->splash(HZ*3, str); rb->splash(HZ*3, str);
rb->strncpy(state->filename,GAME_FILE,MAX_PATH); rb->strlcpy(state->filename,GAME_FILE,MAX_PATH);
} else { } else {
display_board(&new_state); display_board(&new_state);
rb->splash(HZ*2, "Aborted"); rb->splash(HZ*2, "Aborted");

View file

@ -451,7 +451,6 @@ static void init_ci(void)
/* strings and memory */ /* strings and memory */
ci.strcpy = rb->strcpy; ci.strcpy = rb->strcpy;
ci.strncpy = rb->strncpy;
ci.strlen = rb->strlen; ci.strlen = rb->strlen;
ci.strcmp = rb->strcmp; ci.strcmp = rb->strcmp;
ci.strcat = rb->strcat; ci.strcat = rb->strcat;
@ -716,7 +715,7 @@ enum plugin_status plugin_start(const void* parameter)
/* Test all files in the same directory as the file selected by the /* Test all files in the same directory as the file selected by the
user */ user */
rb->strncpy(dirpath,parameter,sizeof(dirpath)); rb->strlcpy(dirpath,parameter,sizeof(dirpath));
ch = rb->strrchr(dirpath,'/'); ch = rb->strrchr(dirpath,'/');
ch[1]=0; ch[1]=0;

View file

@ -133,7 +133,7 @@ char *list_get_name_cb(int selected_item, void* data,
rb->snprintf(buf , buf_len, "%s ...", b); rb->snprintf(buf , buf_len, "%s ...", b);
b[buf_len-10] = t; b[buf_len-10] = t;
} }
else rb->strncpy(buf, b, buf_len); else rb->strlcpy(buf, b, buf_len);
return buf; return buf;
} }

View file

@ -603,8 +603,7 @@ void save_snapshot_file(char *name)
{ {
int type; int type;
rb->strncpy(filenamebuf, name, MAXFILENAME-10); rb->strlcpy(filenamebuf, name, MAXFILENAME-10 + 1);
filenamebuf[MAXFILENAME-10] = '\0';
type = SN_Z80; type = SN_Z80;
if(check_ext(filenamebuf, "z80")) type = SN_Z80; if(check_ext(filenamebuf, "z80")) type = SN_Z80;
@ -642,8 +641,7 @@ void load_snapshot_file_type(char *name, int type)
int snsh; int snsh;
SNFILE snfil; SNFILE snfil;
rb->strncpy(filenamebuf, name, MAXFILENAME-10); rb->strlcpy(filenamebuf, name, MAXFILENAME-10 + 1);
filenamebuf[MAXFILENAME-10] = '\0';
spcf_find_file_type(filenamebuf, &filetype, &type); spcf_find_file_type(filenamebuf, &filetype, &type);
if(type < 0) type = SN_Z80; if(type < 0) type = SN_Z80;

View file

@ -111,8 +111,7 @@ void spcf_read_command_line(const void* parameter)
file_type = extensions[ix].type; file_type = extensions[ix].type;
file_subtype = extensions[ix].subtype; file_subtype = extensions[ix].subtype;
rb->strncpy(filenamebuf, parameter, MAXFILENAME - 10); rb->strlcpy(filenamebuf, parameter, MAXFILENAME - 10 + 1);
filenamebuf[MAXFILENAME-10] = '\0';
if(file_type < 0) file_subtype = -1; if(file_type < 0) file_subtype = -1;
if(!spcf_find_file_type(filenamebuf, &file_type, &file_subtype)) if(!spcf_find_file_type(filenamebuf, &file_type, &file_subtype))
return; return;

View file

@ -594,8 +594,7 @@ void start_play_file_type(char *name, int seg, int type)
{ {
int filetype = FT_TAPEFILE; int filetype = FT_TAPEFILE;
rb->strncpy(tapename, name, MAXFILENAME-10); rb->strlcpy(tapename, name, MAXFILENAME-10 + 1);
tapename[MAXFILENAME-10] = '\0';
currseg = seg; currseg = seg;
tapetype = type; tapetype = type;

View file

@ -510,8 +510,7 @@ static int interpret_tzx_header(byte *hb, struct seginfo *csp)
int blen; int blen;
rb->snprintf(seg_desc,DESC_LEN, "Begin Group: "); rb->snprintf(seg_desc,DESC_LEN, "Begin Group: ");
blen = (int) rb->strlen(seg_desc); blen = (int) rb->strlen(seg_desc);
rb->strncpy(seg_desc+blen, (char *) rbuf, (unsigned) csp->len); rb->strlcpy(seg_desc+blen, (char *) rbuf, (unsigned) csp->len + 1);
seg_desc[csp->len + blen] = '\0';
} }
break; break;
@ -618,8 +617,7 @@ static int interpret_tzx_header(byte *hb, struct seginfo *csp)
return 0; return 0;
} }
csp->ptr += csp->len; csp->ptr += csp->len;
rb->strncpy(seg_desc, (char *) rbuf, (unsigned) csp->len); rb->strlcpy(seg_desc, (char *) rbuf, (unsigned) csp->len + 1);
seg_desc[csp->len] = '\0';
break; break;
case 0x32: case 0x32:

View file

@ -66,8 +66,7 @@ static char* strip_filename(char* buf, int buf_size, const char* fullpath)
} }
len = MIN(sep - fullpath + 1, buf_size - 1); len = MIN(sep - fullpath + 1, buf_size - 1);
strncpy(buf, fullpath, len); strlcpy(buf, fullpath, len + 1);
buf[len] = 0;
return (sep + 1); return (sep + 1);
} }
@ -266,7 +265,7 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string,
if (!found) if (!found)
return false; return false;
strncpy(buf, path, buflen); strlcpy(buf, path, buflen);
logf("Album art found: %s", path); logf("Album art found: %s", path);
return true; return true;
} }

View file

@ -529,7 +529,7 @@ static bool pcmrec_fnq_is_full(void)
/* queue another filename - will overwrite oldest one if full */ /* queue another filename - will overwrite oldest one if full */
static bool pcmrec_fnq_add_filename(const char *filename) static bool pcmrec_fnq_add_filename(const char *filename)
{ {
strncpy(fn_queue + fnq_wr_pos, filename, MAX_PATH); strlcpy(fn_queue + fnq_wr_pos, filename, MAX_PATH);
fnq_wr_pos = FNQ_NEXT(fnq_wr_pos); fnq_wr_pos = FNQ_NEXT(fnq_wr_pos);
if (fnq_rd_pos != fnq_wr_pos) if (fnq_rd_pos != fnq_wr_pos)
@ -550,7 +550,7 @@ static bool pcmrec_fnq_replace_tail(const char *filename)
pos = FNQ_PREV(fnq_wr_pos); pos = FNQ_PREV(fnq_wr_pos);
strncpy(fn_queue + pos, filename, MAX_PATH); strlcpy(fn_queue + pos, filename, MAX_PATH);
return true; return true;
} /* pcmrec_fnq_replace_tail */ } /* pcmrec_fnq_replace_tail */
@ -562,7 +562,7 @@ static bool pcmrec_fnq_get_filename(char *filename)
return false; return false;
if (filename) if (filename)
strncpy(filename, fn_queue + fnq_rd_pos, MAX_PATH); strlcpy(filename, fn_queue + fnq_rd_pos, MAX_PATH);
fnq_rd_pos = FNQ_NEXT(fnq_rd_pos); fnq_rd_pos = FNQ_NEXT(fnq_rd_pos);
return true; return true;
@ -976,7 +976,7 @@ static void pcmrec_new_stream(const char *filename, /* next file name */
bool did_flush = false; /* did a flush occurr? */ bool did_flush = false; /* did a flush occurr? */
if (filename) if (filename)
strncpy(path, filename, MAX_PATH); strlcpy(path, filename, MAX_PATH);
queue_reply(&pcmrec_queue, 0); /* We have all we need */ queue_reply(&pcmrec_queue, 0); /* We have all we need */
data.pre_chunk = NULL; data.pre_chunk = NULL;

View file

@ -1138,7 +1138,7 @@ void radio_load_presets(char *filename)
} }
/* Temporary preset, loaded until player shuts down. */ /* Temporary preset, loaded until player shuts down. */
else if(filename[0] == '/') else if(filename[0] == '/')
strncpy(filepreset, filename, sizeof(filepreset)); strlcpy(filepreset, filename, sizeof(filepreset));
/* Preset from default directory. */ /* Preset from default directory. */
else else
snprintf(filepreset, sizeof(filepreset), "%s/%s.fmr", snprintf(filepreset, sizeof(filepreset), "%s/%s.fmr",
@ -1159,8 +1159,7 @@ void radio_load_presets(char *filename)
{ {
struct fmstation * const fms = &presets[num_presets]; struct fmstation * const fms = &presets[num_presets];
fms->frequency = f; fms->frequency = f;
strncpy(fms->name, name, MAX_FMPRESET_LEN); strlcpy(fms->name, name, MAX_FMPRESET_LEN+1);
fms->name[MAX_FMPRESET_LEN] = '\0';
num_presets++; num_presets++;
} }
} }

View file

@ -964,7 +964,7 @@ static char * reclist_get_name(int selected_item, void * data,
} }
else else
{ {
strncpy(buffer, str(LANG_RECORDING_FILENAME), buffer_len); strlcpy(buffer, str(LANG_RECORDING_FILENAME), buffer_len);
} }
break; break;
} }

View file

@ -218,8 +218,7 @@ long parse_replaygain(const char* key, const char* value,
/* A few characters just isn't interesting... */ /* A few characters just isn't interesting... */
if (len > 1) if (len > 1)
{ {
strncpy(buffer, value, len); strlcpy(buffer, value, len + 1);
buffer[len] = 0;
*p = buffer; *p = buffer;
return len + 1; return len + 1;
} }

View file

@ -77,7 +77,7 @@ static char current_track_path[MAX_PATH];
static void rootmenu_track_changed_callback(void* param) static void rootmenu_track_changed_callback(void* param)
{ {
struct mp3entry *id3 = (struct mp3entry *)param; struct mp3entry *id3 = (struct mp3entry *)param;
strncpy(current_track_path, id3->path, MAX_PATH); strlcpy(current_track_path, id3->path, MAX_PATH);
} }
static int browser(void* param) static int browser(void* param)
{ {
@ -202,7 +202,7 @@ static int browser(void* param)
#endif #endif
case GO_TO_BROWSEPLUGINS: case GO_TO_BROWSEPLUGINS:
filter = SHOW_PLUGINS; filter = SHOW_PLUGINS;
strncpy(folder, PLUGIN_DIR, MAX_PATH); strlcpy(folder, PLUGIN_DIR, MAX_PATH);
break; break;
} }
ret_val = rockbox_browse(folder, filter); ret_val = rockbox_browse(folder, filter);

View file

@ -246,8 +246,7 @@ static bool cfg_string_to_int(int setting_id, int* out, const char* str)
} }
else return false; else return false;
} }
strncpy(temp, start, end-start); strlcpy(temp, start, end-start+1);
temp[end-start] = '\0';
if (!strcmp(str, temp)) if (!strcmp(str, temp))
{ {
*out = count; *out = count;
@ -331,20 +330,18 @@ bool settings_load_config(const char* file, bool apply)
settings[i].filename_setting->prefix, settings[i].filename_setting->prefix,
len)) len))
{ {
strncpy(storage,&value[len],MAX_PATH); strlcpy(storage, &value[len], MAX_PATH);
} }
else strncpy(storage,value,MAX_PATH); else strlcpy(storage, value, MAX_PATH);
} }
else strncpy(storage,value,MAX_PATH); else strlcpy(storage, value, MAX_PATH);
if (settings[i].filename_setting->suffix) if (settings[i].filename_setting->suffix)
{ {
char *s = strcasestr(storage,settings[i].filename_setting->suffix); char *s = strcasestr(storage,settings[i].filename_setting->suffix);
if (s) *s = '\0'; if (s) *s = '\0';
} }
strncpy((char*)settings[i].setting,storage, strlcpy((char*)settings[i].setting, storage,
settings[i].filename_setting->max_len); settings[i].filename_setting->max_len);
((char*)settings[i].setting)
[settings[i].filename_setting->max_len-1] = '\0';
break; break;
} }
} }
@ -379,12 +376,11 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len)
if (value[count] == val) if (value[count] == val)
{ {
if (end == NULL) if (end == NULL)
strncpy(buf, start, buf_len); strlcpy(buf, start, buf_len);
else else
{ {
int len = (buf_len > (end-start))? end-start: buf_len; int len = (buf_len > (end-start))? end-start: buf_len;
strncpy(buf, start, len); strlcpy(buf, start, len+1);
buf[len] = '\0';
} }
return true; return true;
} }
@ -408,12 +404,11 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len)
} }
end = strchr(start,','); end = strchr(start,',');
if (end == NULL) if (end == NULL)
strncpy(buf, start, buf_len); strlcpy(buf, start, buf_len);
else else
{ {
int len = (buf_len > (end-start))? end-start: buf_len; int len = (buf_len > (end-start))? end-start: buf_len;
strncpy(buf, start, len); strlcpy(buf, start, len+1);
buf[len] = '\0';
} }
return true; return true;
} }
@ -468,7 +463,7 @@ bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len)
(char*)settings[i].setting, (char*)settings[i].setting,
settings[i].filename_setting->suffix); settings[i].filename_setting->suffix);
} }
else strncpy(buf,(char*)settings[i].setting, else strlcpy(buf,(char*)settings[i].setting,
settings[i].filename_setting->max_len); settings[i].filename_setting->max_len);
break; break;
} /* switch () */ } /* switch () */
@ -1011,7 +1006,7 @@ void reset_setting(const struct settings_list *setting, void *var)
break; break;
case F_T_CHARPTR: case F_T_CHARPTR:
case F_T_UCHARPTR: case F_T_UCHARPTR:
strncpy((char*)var, setting->default_val.charptr, strlcpy((char*)var, setting->default_val.charptr,
setting->filename_setting->max_len); setting->filename_setting->max_len);
break; break;
} }
@ -1114,7 +1109,7 @@ static void set_option_formatter(char* buf, size_t size, int item, const char* u
{ {
(void)unit; (void)unit;
const unsigned char *text = set_option_options[item].string; const unsigned char *text = set_option_options[item].string;
strncpy(buf, P2STR(text), size); strlcpy(buf, P2STR(text), size);
} }
static int32_t set_option_get_talk_id(int value, int unit) static int32_t set_option_get_talk_id(int value, int unit)
{ {
@ -1177,8 +1172,7 @@ void set_file(const char* filename, char* setting, int maxlen)
(len-extlen > maxlen)) (len-extlen > maxlen))
return; return;
strncpy(setting, fptr, len-extlen); strlcpy(setting, fptr, len-extlen+1);
setting[len-extlen]=0;
settings_save(); settings_save();
} }

View file

@ -439,7 +439,7 @@ static void qs_load_from_cfg(void* var, char*value)
static char* qs_write_to_cfg(void* setting, char*buf, int buf_len) static char* qs_write_to_cfg(void* setting, char*buf, int buf_len)
{ {
const struct settings_list *var = &settings[*(int*)setting]; const struct settings_list *var = &settings[*(int*)setting];
strncpy(buf, var->cfg_name, buf_len); strlcpy(buf, var->cfg_name, buf_len);
return buf; return buf;
} }
static bool qs_is_changed(void* setting, void* defaultval) static bool qs_is_changed(void* setting, void* defaultval)

View file

@ -706,7 +706,7 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx,
if (tag != tag_filename) if (tag != tag_filename)
{ {
ep = (struct tagfile_entry *)&hdr->tags[tag][seek]; ep = (struct tagfile_entry *)&hdr->tags[tag][seek];
strncpy(buf, ep->tag_data, size-1); strlcpy(buf, ep->tag_data, size);
return true; return true;
} }

View file

@ -593,7 +593,7 @@ static bool parse_search(struct menu_entry *entry, const char *str)
menus[menu_count] = buffer_alloc(sizeof(struct menu_root)); menus[menu_count] = buffer_alloc(sizeof(struct menu_root));
new_menu = menus[menu_count]; new_menu = menus[menu_count];
memset(new_menu, 0, sizeof(struct menu_root)); memset(new_menu, 0, sizeof(struct menu_root));
strncpy(new_menu->id, buf, MAX_MENU_ID_SIZE-1); strlcpy(new_menu->id, buf, MAX_MENU_ID_SIZE);
entry->link = menu_count; entry->link = menu_count;
++menu_count; ++menu_count;
@ -839,7 +839,7 @@ static int parse_line(int n, const char *buf, void *parameters)
menu = menus[menu_count]; menu = menus[menu_count];
++menu_count; ++menu_count;
memset(menu, 0, sizeof(struct menu_root)); memset(menu, 0, sizeof(struct menu_root));
strncpy(menu->id, data, MAX_MENU_ID_SIZE-1); strlcpy(menu->id, data, MAX_MENU_ID_SIZE);
} }
if (get_token_str(menu->title, sizeof(menu->title)) < 0) if (get_token_str(menu->title, sizeof(menu->title)) < 0)
@ -1442,8 +1442,8 @@ int tagtree_enter(struct tree_context* c)
csi = menu->items[seek]->si; csi = menu->items[seek]->si;
c->currextra = 0; c->currextra = 0;
strncpy(current_title[c->currextra], dptr->name, strlcpy(current_title[c->currextra], dptr->name,
sizeof(current_title[0]) - 1); sizeof(current_title[0]));
/* Read input as necessary. */ /* Read input as necessary. */
for (i = 0; i < csi->tagorder_count; i++) for (i = 0; i < csi->tagorder_count; i++)
@ -1464,7 +1464,7 @@ int tagtree_enter(struct tree_context* c)
if (source == source_current_path && id3) if (source == source_current_path && id3)
{ {
char *e; char *e;
strncpy(searchstring, id3->path, SEARCHSTR_SIZE); strlcpy(searchstring, id3->path, SEARCHSTR_SIZE);
e = strrchr(searchstring, '/'); e = strrchr(searchstring, '/');
if (e) if (e)
*e = '\0'; *e = '\0';
@ -1477,8 +1477,7 @@ int tagtree_enter(struct tree_context* c)
char **src = (char**)((char*)id3 + offset); char **src = (char**)((char*)id3 + offset);
if (*src) if (*src)
{ {
strncpy(searchstring, *src, SEARCHSTR_SIZE); strlcpy(searchstring, *src, SEARCHSTR_SIZE);
searchstring[SEARCHSTR_SIZE-1] = '\0';
} }
} }
else else
@ -1528,8 +1527,8 @@ int tagtree_enter(struct tree_context* c)
c->dirlevel--; c->dirlevel--;
/* Update the statusbar title */ /* Update the statusbar title */
strncpy(current_title[c->currextra], dptr->name, strlcpy(current_title[c->currextra], dptr->name,
sizeof(current_title[0]) - 1); sizeof(current_title[0]));
break; break;
default: default:

View file

@ -533,7 +533,7 @@ void talk_init(void)
#endif /* CONFIG_CODEC == SWCODEC */ #endif /* CONFIG_CODEC == SWCODEC */
talk_initialized = true; talk_initialized = true;
strncpy((char *) last_lang, (char *)global_settings.lang_file, strlcpy((char *)last_lang, (char *)global_settings.lang_file,
MAX_FILENAME); MAX_FILENAME);
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
@ -755,7 +755,7 @@ static int talk_spell_basename(const char *path,
} }
char buf[MAX_PATH]; char buf[MAX_PATH];
/* Spell only the path component after the last slash */ /* Spell only the path component after the last slash */
strncpy(buf, path, MAX_PATH); strlcpy(buf, path, sizeof(buf));
if(strlen(buf) >1 && buf[strlen(buf)-1] == '/') if(strlen(buf) >1 && buf[strlen(buf)-1] == '/')
/* strip trailing slash */ /* strip trailing slash */
buf[strlen(buf)-1] = '\0'; buf[strlen(buf)-1] = '\0';

View file

@ -505,7 +505,7 @@ char *getcwd(char *buf, int size)
return tc.currdir; return tc.currdir;
else if (size > 0) else if (size > 0)
{ {
strncpy(buf, tc.currdir, size); strlcpy(buf, tc.currdir, size);
return buf; return buf;
} }
else else
@ -924,7 +924,7 @@ int rockbox_browse(const char *root, int dirfilter)
} }
else else
{ {
strncpy(current, LANG_DIR "/english.lng", sizeof(current)); strlcpy(current, LANG_DIR "/english.lng", sizeof(current));
} }
} }
/* Center on currently loaded WPS */ /* Center on currently loaded WPS */

View file

@ -52,7 +52,7 @@ common/strcmp.c
common/strnatcmp.c common/strnatcmp.c
common/strcpy.c common/strcpy.c
common/strncmp.c common/strncmp.c
common/strncpy.c common/strlcpy.c
common/strrchr.c common/strrchr.c
common/strtok.c common/strtok.c
common/strstr.c common/strstr.c

View file

@ -58,8 +58,7 @@ int strip_volume(const char* name, char* namecopy)
name = "/"; /* else this must be the root dir */ name = "/"; /* else this must be the root dir */
} }
strncpy(namecopy, name, MAX_PATH); strlcpy(namecopy, name, MAX_PATH);
namecopy[MAX_PATH-1] = '\0';
return volume; return volume;
} }
@ -120,8 +119,7 @@ DIR_UNCACHED* opendir_uncached(const char* name)
volume = strip_volume(name, namecopy); volume = strip_volume(name, namecopy);
pdir->volumecounter = 0; pdir->volumecounter = 0;
#else #else
strncpy(namecopy,name,sizeof(namecopy)); /* just copy */ strlcpy(namecopy, name, sizeof(namecopy)); /* just copy */
namecopy[sizeof(namecopy)-1] = '\0';
#endif #endif
if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) { if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) {
@ -204,7 +202,7 @@ struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir)
if ( !entry.name[0] ) if ( !entry.name[0] )
return NULL; return NULL;
strncpy(theent->d_name, entry.name, sizeof( theent->d_name ) ); strlcpy(theent->d_name, entry.name, sizeof(theent->d_name));
theent->attribute = entry.attr; theent->attribute = entry.attr;
theent->size = entry.filesize; theent->size = entry.filesize;
theent->startcluster = entry.firstcluster; theent->startcluster = entry.firstcluster;
@ -230,8 +228,7 @@ int mkdir_uncached(const char *name)
return -1; return -1;
} }
strncpy(namecopy,name,sizeof(namecopy)); strlcpy(namecopy, name, sizeof(namecopy));
namecopy[sizeof(namecopy)-1] = 0;
/* Split the base name and the path */ /* Split the base name and the path */
end = strrchr(namecopy, '/'); end = strrchr(namecopy, '/');

View file

@ -232,11 +232,11 @@ static int dircache_scan(IF_MV2(int volume,) struct travel_data *td)
return -2; return -2;
td->pathpos = strlen(dircache_cur_path); td->pathpos = strlen(dircache_cur_path);
strncpy(&dircache_cur_path[td->pathpos], "/", strlcpy(&dircache_cur_path[td->pathpos], "/",
sizeof(dircache_cur_path) - td->pathpos - 1); sizeof(dircache_cur_path) - td->pathpos);
#ifdef SIMULATOR #ifdef SIMULATOR
strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, strlcpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name,
sizeof(dircache_cur_path) - td->pathpos - 2); sizeof(dircache_cur_path) - td->pathpos - 1);
td->newdir = opendir_uncached(dircache_cur_path); td->newdir = opendir_uncached(dircache_cur_path);
if (td->newdir == NULL) if (td->newdir == NULL)
@ -245,8 +245,8 @@ static int dircache_scan(IF_MV2(int volume,) struct travel_data *td)
return -3; return -3;
} }
#else #else
strncpy(&dircache_cur_path[td->pathpos+1], td->entry.name, strlcpy(&dircache_cur_path[td->pathpos+1], td->entry.name,
sizeof(dircache_cur_path) - td->pathpos - 2); sizeof(dircache_cur_path) - td->pathpos - 1);
td->newdir = *td->dir; td->newdir = *td->dir;
if (fat_opendir(IF_MV2(volume,) &td->newdir, if (fat_opendir(IF_MV2(volume,) &td->newdir,
@ -399,7 +399,7 @@ static struct dircache_entry* dircache_get_entry(const char *path,
char* part; char* part;
char* end; char* end;
strncpy(namecopy, path, sizeof(namecopy) - 1); strlcpy(namecopy, path, sizeof(namecopy));
cache_entry = dircache_root; cache_entry = dircache_root;
before = NULL; before = NULL;
@ -926,7 +926,7 @@ static struct dircache_entry* dircache_new_entry(const char *path, int attribute
char *new; char *new;
long last_cache_size = dircache_size; long last_cache_size = dircache_size;
strncpy(basedir, path, sizeof(basedir)-1); strlcpy(basedir, path, sizeof(basedir));
new = strrchr(basedir, '/'); new = strrchr(basedir, '/');
if (new == NULL) if (new == NULL)
{ {
@ -997,8 +997,8 @@ void dircache_bind(int fd, const char *path)
{ {
if (fdbind_idx >= MAX_PENDING_BINDINGS) if (fdbind_idx >= MAX_PENDING_BINDINGS)
return ; return ;
strncpy(fdbind_cache[fdbind_idx].path, path, strlcpy(fdbind_cache[fdbind_idx].path, path,
sizeof(fdbind_cache[fdbind_idx].path)-1); sizeof(fdbind_cache[fdbind_idx].path));
fdbind_cache[fdbind_idx].fd = fd; fdbind_cache[fdbind_idx].fd = fd;
fdbind_idx++; fdbind_idx++;
return ; return ;
@ -1141,7 +1141,7 @@ void dircache_rename(const char *oldpath, const char *newpath)
/* Generate the absolute path for destination if necessary. */ /* Generate the absolute path for destination if necessary. */
if (newpath[0] != '/') if (newpath[0] != '/')
{ {
strncpy(absolute_path, oldpath, sizeof(absolute_path)-1); strlcpy(absolute_path, oldpath, sizeof(absolute_path));
p = strrchr(absolute_path, '/'); p = strrchr(absolute_path, '/');
if (!p) if (!p)
{ {
@ -1151,7 +1151,7 @@ void dircache_rename(const char *oldpath, const char *newpath)
} }
*p = '\0'; *p = '\0';
strncpy(p, absolute_path, sizeof(absolute_path)-1-strlen(p)); strlcpy(p, absolute_path, sizeof(absolute_path)-strlen(p));
newpath = absolute_path; newpath = absolute_path;
} }
@ -1246,7 +1246,7 @@ struct dircache_entry* readdir_cached(DIR_CACHED* dir)
if (regentry == NULL) if (regentry == NULL)
return NULL; return NULL;
strncpy(dir->secondary_entry.d_name, regentry->d_name, MAX_PATH-1); strlcpy(dir->secondary_entry.d_name, regentry->d_name, MAX_PATH);
dir->secondary_entry.size = regentry->size; dir->secondary_entry.size = regentry->size;
dir->secondary_entry.startcluster = regentry->startcluster; dir->secondary_entry.startcluster = regentry->startcluster;
dir->secondary_entry.attribute = regentry->attribute; dir->secondary_entry.attribute = regentry->attribute;
@ -1268,7 +1268,7 @@ struct dircache_entry* readdir_cached(DIR_CACHED* dir)
dir->entry = ce->next; dir->entry = ce->next;
strncpy(dir->secondary_entry.d_name, ce->d_name, MAX_PATH-1); strlcpy(dir->secondary_entry.d_name, ce->d_name, MAX_PATH);
/* Can't do `dir->secondary_entry = *ce` /* Can't do `dir->secondary_entry = *ce`
because that modifies the d_name pointer. */ because that modifies the d_name pointer. */
dir->secondary_entry.size = ce->size; dir->secondary_entry.size = ce->size;

View file

@ -132,8 +132,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache)
} }
#endif #endif
strncpy(pathnamecopy,pathname,sizeof(pathnamecopy)); strlcpy(pathnamecopy, pathname, sizeof(pathnamecopy));
pathnamecopy[sizeof(pathnamecopy)-1] = 0;
/* locate filename */ /* locate filename */
name=strrchr(pathnamecopy+1,'/'); name=strrchr(pathnamecopy+1,'/');

52
firmware/common/strlcpy.c Normal file
View file

@ -0,0 +1,52 @@
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <string.h>
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
strlcpy(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0) {
while (--n != 0) {
if ((*d++ = *s++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}

View file

@ -1183,7 +1183,7 @@ static int write_long_name(struct fat_file* file,
/* shortname entry */ /* shortname entry */
unsigned short date=0, time=0, tenth=0; unsigned short date=0, time=0, tenth=0;
LDEBUGF("Shortname entry: %s\n", shortname); LDEBUGF("Shortname entry: %s\n", shortname);
strncpy(entry + FATDIR_NAME, shortname, 11); memcpy(entry + FATDIR_NAME, shortname, 11);
entry[FATDIR_ATTR] = is_directory?FAT_ATTR_DIRECTORY:0; entry[FATDIR_ATTR] = is_directory?FAT_ATTR_DIRECTORY:0;
entry[FATDIR_NTRES] = 0; entry[FATDIR_NTRES] = 0;
@ -1271,7 +1271,7 @@ static int add_dir_entry(struct fat_dir* dir,
/* The "." and ".." directory entries must not be long names */ /* The "." and ".." directory entries must not be long names */
if(dotdir) { if(dotdir) {
int i; int i;
strncpy(shortname, name, 12); strlcpy(shortname, name, 12);
for(i = strlen(shortname); i < 12; i++) for(i = strlen(shortname); i < 12; i++)
shortname[i] = ' '; shortname[i] = ' ';

View file

@ -1152,7 +1152,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
} }
end = strchr(s->line, '\0'); end = strchr(s->line, '\0');
strncpy(end, string, current_vp->width/2); strlcpy(end, string, current_vp->width/2);
s->vp = current_vp; s->vp = current_vp;
s->y = y; s->y = y;

View file

@ -845,7 +845,7 @@ void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string,
} }
end = strchr(s->line, '\0'); end = strchr(s->line, '\0');
strncpy(end, string, current_vp->width/2); strlcpy(end, string, current_vp->width/2);
s->vp = current_vp; s->vp = current_vp;
s->y = y; s->y = y;

View file

@ -1154,7 +1154,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
} }
end = strchr(s->line, '\0'); end = strchr(s->line, '\0');
strncpy(end, (char *)string, current_vp->width/2); strlcpy(end, (char *)string, current_vp->width/2);
s->vp = current_vp; s->vp = current_vp;
s->y = y; s->y = y;

View file

@ -1167,7 +1167,7 @@ void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string,
} }
end = strchr(s->line, '\0'); end = strchr(s->line, '\0');
strncpy(end, (char *)string, current_vp->width/2); strlcpy(end, (char *)string, current_vp->width/2);
s->vp = current_vp; s->vp = current_vp;
s->y = y; s->y = y;

View file

@ -496,7 +496,7 @@ void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
} }
end = strchr(s->line, '\0'); end = strchr(s->line, '\0');
strncpy(end, string, utf8seek(s->line, current_vp->width)); strlcpy(end, string, utf8seek(s->line, current_vp->width));
s->vp = current_vp; s->vp = current_vp;
s->y = y; s->y = y;

View file

@ -110,7 +110,7 @@ char *create_numbered_filename(char *buffer, const char *path,
char fmtstring[12]; char fmtstring[12];
if (buffer != path) if (buffer != path)
strncpy(buffer, path, MAX_PATH); strlcpy(buffer, path, MAX_PATH);
pathlen = strlen(buffer); pathlen = strlen(buffer);
@ -185,7 +185,7 @@ char *create_datetime_filename(char *buffer, const char *path,
last_tm = *tm; last_tm = *tm;
if (buffer != path) if (buffer != path)
strncpy(buffer, path, MAX_PATH); strlcpy(buffer, path, MAX_PATH);
pathlen = strlen(buffer); pathlen = strlen(buffer);
snprintf(buffer + pathlen, MAX_PATH - pathlen, snprintf(buffer + pathlen, MAX_PATH - pathlen,

View file

@ -35,13 +35,14 @@ char *_EXFUN(strerror,(int));
size_t _EXFUN(strlen,(const char *)); size_t _EXFUN(strlen,(const char *));
char *_EXFUN(strncat,(char *, const char *, size_t)); char *_EXFUN(strncat,(char *, const char *, size_t));
int _EXFUN(strncmp,(const char *, const char *, size_t)); int _EXFUN(strncmp,(const char *, const char *, size_t));
char *_EXFUN(strncpy,(char *, const char *, size_t));
char *_EXFUN(strpbrk,(const char *, const char *)); char *_EXFUN(strpbrk,(const char *, const char *));
char *_EXFUN(strrchr,(const char *, int)); char *_EXFUN(strrchr,(const char *, int));
size_t _EXFUN(strspn,(const char *, const char *)); size_t _EXFUN(strspn,(const char *, const char *));
char *_EXFUN(strstr,(const char *, const char *)); char *_EXFUN(strstr,(const char *, const char *));
char *_EXFUN(strcasestr,(const char *, const char *)); char *_EXFUN(strcasestr,(const char *, const char *));
size_t strlcpy(char *dst, const char *src, size_t siz);
#ifndef _REENT_ONLY #ifndef _REENT_ONLY
char *_EXFUN(strtok,(char *, const char *)); char *_EXFUN(strtok,(char *, const char *));
#endif #endif

View file

@ -145,7 +145,7 @@ void _logf(const char *format, ...)
while(len > MAX_LOGF_ENTRY) while(len > MAX_LOGF_ENTRY)
{ {
ptr = logfbuffer[logfindex]; ptr = logfbuffer[logfindex];
strncpy(ptr, buf + tlen, MAX_LOGF_ENTRY-1); strlcpy(ptr, buf + tlen, MAX_LOGF_ENTRY);
ptr[MAX_LOGF_ENTRY] = LOGF_TERMINATE_CONTINUE_LINE; ptr[MAX_LOGF_ENTRY] = LOGF_TERMINATE_CONTINUE_LINE;
logfindex++; logfindex++;
check_logfindex(); check_logfindex();