Index: apps/codecs.c =================================================================== --- apps/codecs.c (revision 20590) +++ apps/codecs.c (arbetskopia) @@ -123,7 +123,6 @@ /* strings and memory */ strcpy, - strncpy, strlen, strcmp, strcat, Index: apps/playlist.c =================================================================== --- apps/playlist.c (revision 20590) +++ apps/playlist.c (arbetskopia) @@ -1349,8 +1349,7 @@ if (playlist->in_ram && !control_file && max < 0) { - strncpy(tmp_buf, &playlist->buffer[seek], sizeof(tmp_buf)); - tmp_buf[MAX_PATH] = '\0'; + strlcpy(tmp_buf, &playlist->buffer[seek], sizeof(tmp_buf)); max = strlen(tmp_buf) + 1; } else if (max < 0) @@ -1402,8 +1401,7 @@ } } - strncpy(dir_buf, playlist->filename, playlist->dirlen-1); - dir_buf[playlist->dirlen-1] = 0; + strlcpy(dir_buf, playlist->filename, playlist->dirlen); return (format_track_path(buf, tmp_buf, buf_length, max, dir_buf)); } @@ -1471,8 +1469,7 @@ else { /* start with current directory */ - strncpy(dir, playlist->filename, playlist->dirlen-1); - dir[playlist->dirlen-1] = '\0'; + strlcpy(dir, playlist->filename, playlist->dirlen); } /* use the tree browser dircache to load files */ @@ -1671,13 +1668,13 @@ if('/' == src[0]) { - strncpy(dest, src, buf_length); + strlcpy(dest, src, buf_length); } else { /* handle dos style drive letter */ if (':' == src[1]) - strncpy(dest, &src[2], buf_length); + strlcpy(dest, &src[2], buf_length); else if (!strncmp(src, "../", 3)) { /* handle relative paths */ @@ -1904,7 +1901,7 @@ struct playlist_info* playlist = ¤t_playlist; playlist->current = true; - strncpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, + strlcpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, sizeof(playlist->control_filename)); playlist->fd = -1; playlist->control_fd = -1; @@ -2724,7 +2721,7 @@ empty_playlist(¤t_playlist, false); - strncpy(current_playlist.filename, playlist->filename, + strlcpy(current_playlist.filename, playlist->filename, sizeof(current_playlist.filename)); current_playlist.utf8 = playlist->utf8; @@ -3241,7 +3238,7 @@ if (!playlist) playlist = ¤t_playlist; - strncpy(buf, playlist->filename+playlist->dirlen, buf_size); + strlcpy(buf, playlist->filename+playlist->dirlen, buf_size); if (!buf[0]) return NULL; @@ -3261,7 +3258,7 @@ if (!playlist) playlist = ¤t_playlist; - strncpy(buf, playlist->filename, buf_size); + strlcpy(buf, playlist->filename, buf_size); if (!buf[0]) return NULL; Index: apps/codecs.h =================================================================== --- apps/codecs.h (revision 20590) +++ apps/codecs.h (arbetskopia) @@ -75,12 +75,12 @@ #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */ /* 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 backwards compatibility (and please take the opportunity to sort in any 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 */ enum codec_status { @@ -180,7 +180,6 @@ /* strings and memory */ char* (*strcpy)(char *dst, const char *src); - char* (*strncpy)(char *dst, const char *src, size_t length); size_t (*strlen)(const char *str); int (*strcmp)(const char *, const char *); char *(*strcat)(char *s1, const char *s2); Index: apps/cuesheet.c =================================================================== --- apps/cuesheet.c (revision 20590) +++ apps/cuesheet.c (arbetskopia) @@ -84,7 +84,7 @@ return false; } - strncpy(cuepath, trackpath, MAX_PATH); + strlcpy(cuepath, trackpath, MAX_PATH); dot = strrchr(cuepath, '.'); strcpy(dot, ".cue"); @@ -103,7 +103,7 @@ } if (found_cue_path) - strncpy(found_cue_path, cuepath, MAX_PATH); + strlcpy(found_cue_path, cuepath, MAX_PATH); return true; } @@ -205,8 +205,7 @@ } else { - strncpy(dest, string, MAX_NAME*3); - dest[MAX_NAME*3] = '\0'; + strlcpy(dest, string, MAX_NAME*3 + 1); } } } @@ -218,10 +217,10 @@ for (i = 0; i < cue->track_count; i++) { 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') - strncpy(cue->tracks[i].songwriter, cue->songwriter, MAX_NAME*3); + strlcpy(cue->tracks[i].songwriter, cue->songwriter, MAX_NAME*3); } return true; @@ -271,7 +270,7 @@ struct cuesheet *cue = (struct cuesheet *)data; 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 snprintf(buffer, buffer_len, "%02d. %s", selected_item/2+1, cue->tracks[selected_item/2].performer); Index: apps/recorder/radio.c =================================================================== --- apps/recorder/radio.c (revision 20590) +++ apps/recorder/radio.c (arbetskopia) @@ -1141,7 +1141,7 @@ } /* Temporary preset, loaded until player shuts down. */ else if(filename[0] == '/') - strncpy(filepreset, filename, sizeof(filepreset)); + strlcpy(filepreset, filename, sizeof(filepreset)); /* Preset from default directory. */ else snprintf(filepreset, sizeof(filepreset), "%s/%s.fmr", @@ -1162,8 +1162,7 @@ { struct fmstation * const fms = &presets[num_presets]; fms->frequency = f; - strncpy(fms->name, name, MAX_FMPRESET_LEN); - fms->name[MAX_FMPRESET_LEN] = '\0'; + strlcpy(fms->name, name, MAX_FMPRESET_LEN+1); num_presets++; } } Index: apps/recorder/albumart.c =================================================================== --- apps/recorder/albumart.c (revision 20590) +++ apps/recorder/albumart.c (arbetskopia) @@ -60,8 +60,7 @@ } len = MIN(sep - fullpath + 1, buf_size - 1); - strncpy(buf, fullpath, len); - buf[len] = 0; + strlcpy(buf, fullpath, len + 1); return (sep + 1); } @@ -199,7 +198,7 @@ if (!found) return false; - strncpy(buf, path, buflen); + strlcpy(buf, path, buflen); DEBUGF("Album art found: %s\n", path); return true; } Index: apps/recorder/recording.c =================================================================== --- apps/recorder/recording.c (revision 20590) +++ apps/recorder/recording.c (arbetskopia) @@ -966,7 +966,7 @@ } else { - strncpy(buffer, str(LANG_RECORDING_FILENAME), buffer_len); + strlcpy(buffer, str(LANG_RECORDING_FILENAME), buffer_len); } break; } Index: apps/recorder/pcm_record.c =================================================================== --- apps/recorder/pcm_record.c (revision 20590) +++ apps/recorder/pcm_record.c (arbetskopia) @@ -529,7 +529,7 @@ /* queue another filename - will overwrite oldest one if full */ 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); if (fnq_rd_pos != fnq_wr_pos) @@ -550,7 +550,7 @@ pos = FNQ_PREV(fnq_wr_pos); - strncpy(fn_queue + pos, filename, MAX_PATH); + strlcpy(fn_queue + pos, filename, MAX_PATH); return true; } /* pcmrec_fnq_replace_tail */ @@ -562,7 +562,7 @@ return false; 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); return true; @@ -976,7 +976,7 @@ bool did_flush = false; /* did a flush occurr? */ if (filename) - strncpy(path, filename, MAX_PATH); + strlcpy(path, filename, MAX_PATH); queue_reply(&pcmrec_queue, 0); /* We have all we need */ data.pre_chunk = NULL; Index: apps/tree.c =================================================================== --- apps/tree.c (revision 20590) +++ apps/tree.c (arbetskopia) @@ -508,7 +508,7 @@ return tc.currdir; else if (size > 0) { - strncpy(buf, tc.currdir, size); + strlcpy(buf, tc.currdir, size); return buf; } else Index: apps/metadata/mp3.c =================================================================== --- apps/metadata/mp3.c (revision 20590) +++ apps/metadata/mp3.c (arbetskopia) @@ -309,8 +309,7 @@ value_len = bufferpos - (tag - entry->id3v2buf); if (!strcasecmp(tag, "ALBUM ARTIST")) { - strncpy(tag, value, value_len); - tag[value_len - 1] = 0; + strlcpy(tag, value, value_len); entry->albumartist = tag; #if CONFIG_CODEC == SWCODEC } else { @@ -1114,7 +1113,7 @@ memset(entry, 0, sizeof(struct mp3entry)); #endif - strncpy(entry->path, filename, sizeof(entry->path)); + strlcpy(entry->path, filename, sizeof(entry->path)); entry->title = NULL; entry->filesize = filesize(fd); Index: apps/metadata/metadata_common.c =================================================================== --- apps/metadata/metadata_common.c (revision 20590) +++ apps/metadata/metadata_common.c (arbetskopia) @@ -303,10 +303,9 @@ if (len > 0) { - strncpy(buf, value, len); - buf[len] = 0; - *p = buf; len++; + strlcpy(buf, value, len); + *p = buf; } else { Index: apps/settings.c =================================================================== --- apps/settings.c (revision 20590) +++ apps/settings.c (arbetskopia) @@ -247,8 +247,7 @@ } else return false; } - strncpy(temp, start, end-start); - temp[end-start] = '\0'; + strlcpy(temp, start, end-start+1); if (!strcmp(str, temp)) { *out = count; @@ -332,20 +331,18 @@ settings[i].filename_setting->prefix, 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) { char *s = strcasestr(storage,settings[i].filename_setting->suffix); if (s) *s = '\0'; } - strncpy((char*)settings[i].setting,storage, + strlcpy((char*)settings[i].setting, storage, settings[i].filename_setting->max_len); - ((char*)settings[i].setting) - [settings[i].filename_setting->max_len-1] = '\0'; break; } } @@ -380,12 +377,11 @@ if (value[count] == val) { if (end == NULL) - strncpy(buf, start, buf_len); + strlcpy(buf, start, buf_len); else { int len = (buf_len > (end-start))? end-start: buf_len; - strncpy(buf, start, len); - buf[len] = '\0'; + strlcpy(buf, start, len+1); } return true; } @@ -409,12 +405,11 @@ } end = strchr(start,','); if (end == NULL) - strncpy(buf, start, buf_len); + strlcpy(buf, start, buf_len); else { int len = (buf_len > (end-start))? end-start: buf_len; - strncpy(buf, start, len); - buf[len] = '\0'; + strlcpy(buf, start, len+1); } return true; } @@ -469,7 +464,7 @@ (char*)settings[i].setting, 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); break; } /* switch () */ @@ -996,7 +991,7 @@ break; case F_T_CHARPTR: case F_T_UCHARPTR: - strncpy((char*)var, setting->default_val.charptr, + strlcpy((char*)var, setting->default_val.charptr, setting->filename_setting->max_len); break; } @@ -1099,7 +1094,7 @@ { (void)unit; 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) { @@ -1159,12 +1154,11 @@ } if(ptr == fptr) extlen = 0; - if (strncasecmp(ROCKBOX_DIR, filename ,strlen(ROCKBOX_DIR)) || + if (strncasecmp(ROCKBOX_DIR, filename, strlen(ROCKBOX_DIR)) || (len-extlen > maxlen)) return; - strncpy(setting, fptr, len-extlen); - setting[len-extlen]=0; + strlcpy(setting, fptr, len-extlen+1); settings_save(); } Index: apps/plugins/mp3_encoder.c =================================================================== --- apps/plugins/mp3_encoder.c (revision 20590) +++ apps/plugins/mp3_encoder.c (arbetskopia) @@ -2399,9 +2399,8 @@ void get_mp3_filename(const char *wav_name) { - int slen = rb->strlen(wav_name); - rb->strncpy(mp3_name, wav_name, 79); - rb->strncpy(mp3_name + slen - 4, ".mp3", 5); + rb->strlcpy(mp3_name, wav_name, sizeof(mp3_name)); + rb->strlcpy(mp3_name + rb->strlen(mp3_name) - 4, ".mp3", 5); } #if CONFIG_KEYPAD == IRIVER_H100_PAD || CONFIG_KEYPAD == IRIVER_H300_PAD Index: apps/plugins/keybox.c =================================================================== --- apps/plugins/keybox.c (revision 20590) +++ apps/plugins/keybox.c (arbetskopia) @@ -337,7 +337,7 @@ struct md5_s key_md5; 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)); @@ -421,7 +421,7 @@ break; } - rb->strncpy(entry->title, start, FIELD_LEN); + rb->strlcpy(entry->title, start, FIELD_LEN); start = end + 1; end = rb->strchr(start, '\0'); /* find eol */ @@ -431,7 +431,7 @@ break; } - rb->strncpy(entry->name, start, FIELD_LEN); + rb->strlcpy(entry->name, start, FIELD_LEN); start = end + 1; end = rb->strchr(start, '\0'); /* find eol */ @@ -440,7 +440,7 @@ { break; } - rb->strncpy(entry->password, start, FIELD_LEN); + rb->strlcpy(entry->password, start, FIELD_LEN); start = end + 1; entry->used = true; if (i + 1 < MAX_ENTRIES - 1) @@ -472,13 +472,13 @@ for (i = 0; i < pw_list.num_entries; i++) { len = rb->strlen(entry->title); - rb->strncpy(p, entry->title, len+1); + rb->strlcpy(p, entry->title, len+1); p += len+1; len = rb->strlen(entry->name); - rb->strncpy(p, entry->name, len+1); + rb->strlcpy(p, entry->name, len+1); p += len+1; len = rb->strlen(entry->password); - rb->strncpy(p, entry->password, len+1); + rb->strlcpy(p, entry->password, len+1); p += len+1; if (entry->next) entry = entry->next; @@ -517,7 +517,7 @@ } else { - rb->strncpy(pw_buf, buf[0], buflen); + rb->strlcpy(pw_buf, buf[0], buflen); hash_pw(&pwhash); return 0; } Index: apps/plugins/random_folder_advance_config.c =================================================================== --- apps/plugins/random_folder_advance_config.c (revision 20590) +++ apps/plugins/random_folder_advance_config.c (arbetskopia) @@ -86,7 +86,7 @@ /* check if path is removed directory, if so dont enter it */ rb->snprintf(path, MAX_PATH, "%s/%s", fullpath, entry->d_name); 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++) { if(!rb->strcmp(path, removed_dirs[i])) @@ -141,8 +141,8 @@ (num_replaced_dirs < MAX_REMOVED_DIRS)) { num_replaced_dirs ++; - rb->strncpy(removed_dirs[num_replaced_dirs - 1], line + 2, - rb->strlen(line)); + rb->strlcpy(removed_dirs[num_replaced_dirs - 1], line + 2, + sizeof(line)); } } rb->close(fd2); @@ -157,7 +157,7 @@ { /* remove preceeding '/'s from the line */ 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); @@ -237,7 +237,7 @@ char *list_get_name_cb(int selected_item, void* data, char* buf, size_t buf_len) { (void)data; - rb->strncpy(buf, list->folder[selected_item], buf_len); + rb->strlcpy(buf, list->folder[selected_item], buf_len); return buf; } Index: apps/plugins/dict.c =================================================================== --- apps/plugins/dict.c (revision 20590) +++ apps/plugins/dict.c (arbetskopia) @@ -282,8 +282,7 @@ while (1) { /* copy one lcd line */ - rb->strncpy(output, ptr, display_columns); - output[display_columns] = '\0'; + rb->strlcpy(output, ptr, display_columns + 1); /* typecast to kill a warning... */ if((int)rb->strlen(ptr) < display_columns) Index: apps/plugins/zxbox/snapshot.c =================================================================== --- apps/plugins/zxbox/snapshot.c (revision 20590) +++ apps/plugins/zxbox/snapshot.c (arbetskopia) @@ -603,8 +603,7 @@ { int type; - rb->strncpy(filenamebuf, name, MAXFILENAME-10); - filenamebuf[MAXFILENAME-10] = '\0'; + rb->strlcpy(filenamebuf, name, MAXFILENAME-10 + 1); type = SN_Z80; if(check_ext(filenamebuf, "z80")) type = SN_Z80; @@ -642,8 +641,7 @@ int snsh; SNFILE snfil; - rb->strncpy(filenamebuf, name, MAXFILENAME-10); - filenamebuf[MAXFILENAME-10] = '\0'; + rb->strlcpy(filenamebuf, name, MAXFILENAME-10 + 1); spcf_find_file_type(filenamebuf, &filetype, &type); if(type < 0) type = SN_Z80; Index: apps/plugins/zxbox/spconf.c =================================================================== --- apps/plugins/zxbox/spconf.c (revision 20590) +++ apps/plugins/zxbox/spconf.c (arbetskopia) @@ -111,8 +111,7 @@ file_type = extensions[ix].type; file_subtype = extensions[ix].subtype; - rb->strncpy(filenamebuf, parameter, MAXFILENAME - 10); - filenamebuf[MAXFILENAME-10] = '\0'; + rb->strlcpy(filenamebuf, parameter, MAXFILENAME - 10 + 1); if(file_type < 0) file_subtype = -1; if(!spcf_find_file_type(filenamebuf, &file_type, &file_subtype)) return; Index: apps/plugins/zxbox/sptape.c =================================================================== --- apps/plugins/zxbox/sptape.c (revision 20590) +++ apps/plugins/zxbox/sptape.c (arbetskopia) @@ -594,8 +594,7 @@ { int filetype = FT_TAPEFILE; - rb->strncpy(tapename, name, MAXFILENAME-10); - tapename[MAXFILENAME-10] = '\0'; + rb->strlcpy(tapename, name, MAXFILENAME-10 + 1); currseg = seg; tapetype = type; Index: apps/plugins/zxbox/tapefile.c =================================================================== --- apps/plugins/zxbox/tapefile.c (revision 20590) +++ apps/plugins/zxbox/tapefile.c (arbetskopia) @@ -510,8 +510,7 @@ int blen; rb->snprintf(seg_desc,DESC_LEN, "Begin Group: "); blen = (int) rb->strlen(seg_desc); - rb->strncpy(seg_desc+blen, (char *) rbuf, (unsigned) csp->len); - seg_desc[csp->len + blen] = '\0'; + rb->strlcpy(seg_desc+blen, (char *) rbuf, (unsigned) csp->len + 1); } break; @@ -618,8 +617,7 @@ return 0; } csp->ptr += csp->len; - rb->strncpy(seg_desc, (char *) rbuf, (unsigned) csp->len); - seg_desc[csp->len] = '\0'; + rb->strlcpy(seg_desc, (char *) rbuf, (unsigned) csp->len + 1); break; case 0x32: Index: apps/plugins/sudoku/sudoku.c =================================================================== --- apps/plugins/sudoku/sudoku.c (revision 20590) +++ apps/plugins/sudoku/sudoku.c (arbetskopia) @@ -604,7 +604,7 @@ { 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 (c=0;c<9;c++) { state->startboard[r][c]=default_game[r][c]; @@ -627,7 +627,7 @@ { 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 (c=0;c<9;c++) { state->startboard[r][c]='0'; @@ -720,7 +720,7 @@ return(false); } - rb->strncpy(state->filename,filename,MAX_PATH); + rb->strlcpy(state->filename,filename,MAX_PATH); n=rb->read(fd,buf,300); if (n <= 0) { return(false); @@ -1112,7 +1112,7 @@ rb->snprintf(str,sizeof(str),"Difficulty: %s",difficulty); display_board(state); rb->splash(HZ*3, str); - rb->strncpy(state->filename,GAME_FILE,MAX_PATH); + rb->strlcpy(state->filename,GAME_FILE,MAX_PATH); } else { display_board(&new_state); rb->splash(HZ*2, "Aborted"); Index: apps/plugins/chessbox/chessbox_pgn.c =================================================================== --- apps/plugins/chessbox/chessbox_pgn.c (revision 20590) +++ apps/plugins/chessbox/chessbox_pgn.c (arbetskopia) @@ -543,7 +543,7 @@ rb->snprintf(text_buffer, 50,"%s vs. %s (%s)", temp_node->white_player, temp_node->black_player, temp_node->game_date); - rb->strncpy(buffer, text_buffer, buffer_len); + rb->strlcpy(buffer, text_buffer, buffer_len); return buffer; } Index: apps/plugins/mpegplayer/mpeg_settings.c =================================================================== --- apps/plugins/mpegplayer/mpeg_settings.c (revision 20590) +++ apps/plugins/mpegplayer/mpeg_settings.c (arbetskopia) @@ -344,7 +344,7 @@ int value, const char *input) { if (value < 0) - rb->strncpy(buf, BACKLIGHT_OPTION_DEFAULT, length); + rb->strlcpy(buf, BACKLIGHT_OPTION_DEFAULT, length); else rb->snprintf(buf, length, "%d", value + MIN_BRIGHTNESS_SETTING); Index: apps/plugins/splitedit.c =================================================================== --- apps/plugins/splitedit.c (revision 20590) +++ apps/plugins/splitedit.c (arbetskopia) @@ -780,11 +780,11 @@ bool part2_save = true; /* 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); /* 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); while (!exit_request) Index: apps/plugins/pictureflow.c =================================================================== --- apps/plugins/pictureflow.c (revision 20590) +++ apps/plugins/pictureflow.c (arbetskopia) @@ -714,7 +714,7 @@ { if ( slide_index == -1 ) { - rb->strncpy( buf, EMPTY_SLIDE, buflen ); + rb->strlcpy( buf, EMPTY_SLIDE, buflen ); } if (!rb->tagcache_search(&tcs, tag_filename)) Index: apps/plugins/goban/sgf_output.c =================================================================== --- apps/plugins/goban/sgf_output.c (revision 20590) +++ apps/plugins/goban/sgf_output.c (arbetskopia) @@ -130,7 +130,7 @@ { 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)); write_file (sgf_fd, buffer, rb->strlen (buffer)); Index: apps/plugins/shortcuts/shortcuts_common.c =================================================================== --- apps/plugins/shortcuts/shortcuts_common.c (revision 20590) +++ apps/plugins/shortcuts/shortcuts_common.c (arbetskopia) @@ -213,8 +213,7 @@ DEBUGF("Bad entry: pathlen=%d, displen=%d\n", path_len, disp_len); return false; } - rb->strncpy(entry->path, path, path_len); - entry->path[path_len] = '\0'; + rb->strlcpy(entry->path, path, path_len + 1); rb->strcpy(entry->disp, disp); /* Safe since we've checked the length */ entry->explicit_disp = expl; return true; @@ -295,15 +294,14 @@ /* Too long name */ return false; } - rb->strncpy(name, line, name_len); - name[name_len] = '\0'; + rb->strlcpy(name, line, name_len + 1); val_len = rb->strlen(line) - name_len - NAME_VALUE_SEPARATOR_LEN; if (val_len >= valuesize) { /* Too long value */ 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; } Index: apps/plugins/doom/r_data.c =================================================================== --- apps/plugins/doom/r_data.c (revision 20590) +++ apps/plugins/doom/r_data.c (arbetskopia) @@ -415,7 +415,7 @@ for (i=0 ; imemcmp((a),(b),(c)) #define memchr(a,b,c) rb->memchr((a),(b),(c)) #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 strcmp(a,b) rb->strcmp((a),(b)) #define strncmp(a,b,c) rb->strncmp((a),(b),(c)) Index: apps/plugins/doom/w_wad.c =================================================================== --- apps/plugins/doom/w_wad.c (revision 20590) +++ apps/plugins/doom/w_wad.c (arbetskopia) @@ -224,7 +224,7 @@ lump_p->data = NULL; // killough 1/31/98 #endif lump_p->namespace = ns_global; // killough 4/17/98 - strncpy (lump_p->name, fileinfo->name, 8); + memcpy(lump_p->name, fileinfo->name, 8); lump_p->source = source; // Ty 08/29/98 lump_p->locks = 0; // CPhipps - initialise locks } @@ -260,7 +260,7 @@ { // If this is the first start marker, add start marker to marked lumps if (!num_marked) { - strncpy(marked->name, start_marker, 8); + strlcpy(marked->name, start_marker, 8); marked->size = 0; // killough 3/20/98: force size to be 0 marked->namespace = ns_global; // killough 4/17/98 num_marked = 1; @@ -293,7 +293,7 @@ { lumpinfo[numlumps].size = 0; // killough 3/20/98: force size to be 0 lumpinfo[numlumps].namespace = ns_global; // killough 4/17/98 - strncpy(lumpinfo[numlumps++].name, end_marker, 8); + strlcpy(lumpinfo[numlumps++].name, end_marker, 8); } } @@ -671,7 +671,7 @@ filelump_t fileinfo = {0}; fileinfo.filepos = LONG(filepos); fileinfo.size = LONG(predefined_lumps[i].size); - strncpy(fileinfo.name, predefined_lumps[i].name, 8); + strlcpy(fileinfo.name, predefined_lumps[i].name, 8); write(handle, &fileinfo, sizeof(fileinfo)); filepos += predefined_lumps[i].size; } Index: apps/plugins/lib/wrappers.h =================================================================== --- apps/plugins/lib/wrappers.h (revision 20590) +++ apps/plugins/lib/wrappers.h (arbetskopia) @@ -47,7 +47,6 @@ #define strcpy rb->strcpy #define strip_extension rb->strip_extension #define strlen rb->strlen -#define strncpy rb->strncpy #define strrchr rb->strrchr #endif Index: apps/plugins/lib/highscore.c =================================================================== --- apps/plugins/lib/highscore.c (revision 20590) +++ apps/plugins/lib/highscore.c (arbetskopia) @@ -75,7 +75,7 @@ *ptr = 0; ptr++; - rb->strncpy(scores[i].name, name, sizeof(scores[i].name)); + rb->strlcpy(scores[i].name, name, sizeof(scores[i].name)); DEBUGF("%s\n", scores[i].name); score = ptr; Index: apps/plugins/lib/configfile.c =================================================================== --- apps/plugins/lib/configfile.c (revision 20590) +++ apps/plugins/lib/configfile.c (arbetskopia) @@ -139,7 +139,7 @@ break; case TYPE_STRING: - rb->strncpy(cfg[i].string, val, cfg[i].max); + rb->strlcpy(cfg[i].string, val, cfg[i].max); break; } } Index: apps/plugins/rockboy/rockmacros.h =================================================================== --- apps/plugins/rockboy/rockmacros.h (revision 20590) +++ apps/plugins/rockboy/rockmacros.h (arbetskopia) @@ -67,7 +67,7 @@ #define strcat(a,b) rb->strcat((a),(b)) #define memset(a,b,c) rb->memset((a),(b),(c)) #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 strcmp(a,b) rb->strcmp((a),(b)) #define strchr(a,b) rb->strchr((a),(b)) Index: apps/plugins/rockboy/menu.c =================================================================== --- apps/plugins/rockboy/menu.c (revision 20590) +++ apps/plugins/rockboy/menu.c (arbetskopia) @@ -173,7 +173,7 @@ char name_buf[40]; /* munge state file name */ - strncpy(name_buf, rom.name, 40); + strlcpy(name_buf, rom.name, 40); name_buf[16] = '\0'; munge_name(name_buf, strlen(name_buf)); @@ -219,7 +219,7 @@ /* build description buffer */ memset(desc_buf, 0, 20); if (desc) - strncpy(desc_buf, desc, 20); + strlcpy(desc_buf, desc, 20); /* save state */ write(fd, desc_buf, 20); @@ -250,7 +250,7 @@ if (rb->kbd_input(desc_buf, 20) || !strlen(desc_buf)) { memset(desc_buf, 0, 20); - strncpy(desc_buf, "Untitled", 20); + strlcpy(desc_buf, "Untitled", 20); } /* load/save file */ Index: apps/plugins/sokoban.c =================================================================== --- apps/plugins/sokoban.c (revision 20590) +++ apps/plugins/sokoban.c (arbetskopia) @@ -680,7 +680,8 @@ 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.player.row = 0; @@ -1017,8 +1018,8 @@ /* Create dir if it doesn't exist */ if ((loc = rb->strrchr(filename, '/')) != NULL) { - rb->strncpy(dirname, filename, loc - filename); - dirname[loc - filename] = '\0'; + rb->strlcpy(dirname, filename, loc - filename + 1); + if(!(dir = rb->opendir(dirname))) rb->mkdir(dirname); else @@ -1073,7 +1074,9 @@ if (rb->strncmp(buf, "Sokoban", 7) != 0) { 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)) return false; Index: apps/plugins/test_codec.c =================================================================== --- apps/plugins/test_codec.c (revision 20590) +++ apps/plugins/test_codec.c (arbetskopia) @@ -451,7 +451,6 @@ /* strings and memory */ ci.strcpy = rb->strcpy; - ci.strncpy = rb->strncpy; ci.strlen = rb->strlen; ci.strcmp = rb->strcmp; ci.strcat = rb->strcat; @@ -716,7 +715,7 @@ /* Test all files in the same directory as the file selected by the user */ - rb->strncpy(dirpath,parameter,sizeof(dirpath)); + rb->strlcpy(dirpath,parameter,sizeof(dirpath)); ch = rb->strrchr(dirpath,'/'); ch[1]=0; Index: apps/plugins/invadrox.c =================================================================== --- apps/plugins/invadrox.c (revision 20590) +++ apps/plugins/invadrox.c (arbetskopia) @@ -1600,7 +1600,7 @@ if (highscore_load(HISCOREFILE, &hiscore, 1) < 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.level = 1; } Index: apps/plugins/rockpaint.c =================================================================== --- apps/plugins/rockpaint.c (revision 20590) +++ apps/plugins/rockpaint.c (arbetskopia) @@ -776,7 +776,7 @@ {*/ /* this is a file */ bbuf[rb->strlen(bbuf)-1] = '\0'; - rb->strncpy( dst, bbuf, dst_size ); + rb->strlcpy( dst, bbuf, dst_size ); return true; /*} else if( errno == EACCES || errno == ENOENT ) Index: apps/plugins/text_editor.c =================================================================== --- apps/plugins/text_editor.c (revision 20590) +++ apps/plugins/text_editor.c (arbetskopia) @@ -133,7 +133,7 @@ rb->snprintf(buf , buf_len, "%s ...", b); b[buf_len-10] = t; } - else rb->strncpy(buf, b, buf_len); + else rb->strlcpy(buf, b, buf_len); return buf; } char filename[MAX_PATH]; Index: apps/plugins/properties.c =================================================================== --- apps/plugins/properties.c (revision 20590) +++ apps/plugins/properties.c (arbetskopia) @@ -70,8 +70,7 @@ char* ptr = rb->strrchr(selected_file, '/') + 1; int dirlen = (ptr - selected_file); - rb->strncpy(tstr, selected_file, dirlen); - tstr[dirlen] = 0; + rb->strlcpy(tstr, selected_file, dirlen + 1); dir = rb->opendir(tstr); if (dir) @@ -212,7 +211,7 @@ { DPS dps; char tstr[64]; - rb->strncpy(dps.dirname, selected_file, MAX_PATH); + rb->strlcpy(dps.dirname, selected_file, MAX_PATH); dps.len = MAX_PATH; dps.dc = 0; dps.fc = 0; @@ -220,7 +219,7 @@ if(false == _dir_properties(&dps)) 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_filecount, sizeof str_filecount, "Files: %d", dps.fc); rb->snprintf(str_size, sizeof str_size, "Size: %s", @@ -236,35 +235,35 @@ switch(selected_item) { case 0: - rb->strncpy(buffer, str_dirname, buffer_len); + rb->strlcpy(buffer, str_dirname, buffer_len); break; case 1: - rb->strncpy(buffer, its_a_dir ? str_dircount : str_filename, + rb->strlcpy(buffer, its_a_dir ? str_dircount : str_filename, buffer_len); break; 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; 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; case 4: - rb->strncpy(buffer, its_a_dir ? "" : str_time, buffer_len); + rb->strlcpy(buffer, its_a_dir ? "" : str_time, buffer_len); break; case 5: - rb->strncpy(buffer, its_a_dir ? "" : str_artist, buffer_len); + rb->strlcpy(buffer, its_a_dir ? "" : str_artist, buffer_len); break; case 6: - rb->strncpy(buffer, its_a_dir ? "" : str_title, buffer_len); + rb->strlcpy(buffer, its_a_dir ? "" : str_title, buffer_len); break; case 7: - rb->strncpy(buffer, its_a_dir ? "" : str_album, buffer_len); + rb->strlcpy(buffer, its_a_dir ? "" : str_album, buffer_len); break; case 8: - rb->strncpy(buffer, its_a_dir ? "" : str_duration, buffer_len); + rb->strlcpy(buffer, its_a_dir ? "" : str_duration, buffer_len); break; default: - rb->strncpy(buffer, "ERROR", buffer_len); + rb->strlcpy(buffer, "ERROR", buffer_len); break; } return buffer; @@ -285,8 +284,7 @@ struct dirent* entry; char* ptr = rb->strrchr(file, '/') + 1; int dirlen = (ptr - file); - rb->strncpy(str_dirname, file, dirlen); - str_dirname[dirlen] = 0; + rb->strlcpy(str_dirname, file, dirlen + 1); dir = rb->opendir(str_dirname); if (dir) Index: apps/onplay.c =================================================================== --- apps/onplay.c (revision 20590) +++ apps/onplay.c (arbetskopia) @@ -533,7 +533,7 @@ { char pathname[MAX_PATH]; /* space to go deep */ cpu_boost(true); - strncpy(pathname, file_to_delete, sizeof pathname); + strlcpy(pathname, file_to_delete, sizeof(pathname)); res = remove_dir(pathname, sizeof(pathname)); cpu_boost(false); } @@ -579,7 +579,7 @@ char newname[MAX_PATH]; char* ptr = strrchr(selected_file, '/') + 1; 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 (!strlen(newname + pathlen) || (rename(selected_file, newname) < 0)) { @@ -639,7 +639,7 @@ static bool clipboard_clip(bool copy) { 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_is_copy = copy; @@ -896,15 +896,15 @@ } else { - strncpy(srcpath, clipboard_selection, sizeof(srcpath)); - strncpy(targetpath, target, sizeof(targetpath)); + strlcpy(srcpath, clipboard_selection, sizeof(srcpath)); + strlcpy(targetpath, target, sizeof(targetpath)); success = clipboard_pastedirectory(srcpath, sizeof(srcpath), target, sizeof(targetpath), 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)); } } @@ -1027,7 +1027,7 @@ #ifdef HAVE_RECORDING static bool set_recdir(void) { - strncpy(global_settings.rec_directory, + strlcpy(global_settings.rec_directory, selected_file, MAX_FILENAME+1); settings_save(); return false; Index: apps/gui/buttonbar.c =================================================================== --- apps/gui/buttonbar.c (revision 20590) +++ apps/gui/buttonbar.c (arbetskopia) @@ -86,18 +86,15 @@ gui_buttonbar_unset(buttonbar); if(caption1) { - strncpy(buttonbar->caption[0], caption1, 7); - buttonbar->caption[0][7] = 0; + strlcpy(buttonbar->caption[0], caption1, BUTTONBAR_CAPTION_LENGTH); } if(caption2) { - strncpy(buttonbar->caption[1], caption2, 7); - buttonbar->caption[1][7] = 0; + strlcpy(buttonbar->caption[1], caption2, BUTTONBAR_CAPTION_LENGTH); } if(caption3) { - strncpy(buttonbar->caption[2], caption3, 7); - buttonbar->caption[2][7] = 0; + strlcpy(buttonbar->caption[2], caption3, BUTTONBAR_CAPTION_LENGTH); } } Index: apps/gui/gwps-common.c =================================================================== --- apps/gui/gwps-common.c (revision 20590) +++ apps/gui/gwps-common.c (arbetskopia) @@ -681,8 +681,7 @@ return NULL; len = MIN(last_sep - sep, buf_size - 1); - strncpy(buf, sep + 1, len); - buf[len] = 0; + strlcpy(buf, sep + 1, len + 1); return buf; } @@ -1197,12 +1196,12 @@ { /* we need 11 characters (full line) for progress-bar */ - strncpy(buf, " ", buf_size); + strlcpy(buf, " ", buf_size); } else { /* Tell the user if we have an OldPlayer */ - strncpy(buf, " ", buf_size); + strlcpy(buf, " ", buf_size); } return buf; #endif @@ -1268,11 +1267,11 @@ break; case 2: case 4: - strncpy(buf, id3->track_gain_string, buf_size); + strlcpy(buf, id3->track_gain_string, buf_size); break; case 3: case 5: - strncpy(buf, id3->album_gain_string, buf_size); + strlcpy(buf, id3->album_gain_string, buf_size); break; } return buf; Index: apps/gui/option_select.c =================================================================== --- apps/gui/option_select.c (revision 20590) +++ apps/gui/option_select.c (arbetskopia) @@ -77,7 +77,7 @@ if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) { 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); } #if 0 /* probably dont need this one */ @@ -138,7 +138,7 @@ const struct choice_setting *info = setting->choice_setting; 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 { @@ -150,7 +150,7 @@ { int value= (int)temp_var; char *val = P2STR(setting->choice_setting->desc[value]); - strncpy(buffer, val, buf_len); + strlcpy(buffer, val, buf_len); } } return buffer; Index: apps/gui/statusbar.c =================================================================== --- apps/gui/statusbar.c (revision 20590) +++ apps/gui/statusbar.c (arbetskopia) @@ -614,7 +614,7 @@ snprintf(buffer, sizeof(buffer), "%02d:%02d", hour, minute); } else { - strncpy(buffer, "--:--", sizeof buffer); + strlcpy(buffer, "--:--", sizeof(buffer)); } display->setfont(FONT_SYSFIXED); display->getstringsize(buffer, &width, &height); @@ -623,7 +623,6 @@ STATUSBAR_Y_POS, buffer); } display->setfont(FONT_UI); - } #endif @@ -755,14 +754,14 @@ if (global_settings.rec_source == AUDIO_SRC_SPDIF) { /* Can't measure S/PDIF sample rate on Archos/Sim yet */ - strncpy(buffer, "--", sizeof(buffer)); + strlcpy(buffer, "--", sizeof(buffer)); } else #endif /* HAVE_SPDIF_IN */ { static char const * const freq_strings[12] = { "44", "48", "32", "22", "24", "16" }; - strncpy(buffer, freq_strings[global_settings.rec_frequency], + strlcpy(buffer, freq_strings[global_settings.rec_frequency], sizeof(buffer)); } Index: apps/gui/wps_parser.c =================================================================== --- apps/gui/wps_parser.c (revision 20590) +++ apps/gui/wps_parser.c (arbetskopia) @@ -1398,8 +1398,7 @@ break; } - strncpy(stringbuf, string_start, len); - *(stringbuf + len) = '\0'; + strlcpy(stringbuf, string_start, len+1); data->strings[data->num_strings] = stringbuf; stringbuf += len + 1; @@ -1686,12 +1685,10 @@ #ifdef HAVE_LCD_BITMAP /* get the bitmap dir */ char bmpdir[MAX_PATH]; - size_t bmpdirlen; char *dot = strrchr(buf, '.'); - bmpdirlen = dot - buf; - strncpy(bmpdir, buf, dot - buf); - bmpdir[bmpdirlen] = 0; + strlcpy(bmpdir, buf, dot - buf + 1); + /* load the bitmaps that were found by the parsing */ if (!load_wps_bitmaps(wps_data, bmpdir)) { wps_reset(wps_data); Index: apps/menu.c =================================================================== --- apps/menu.c (revision 20590) +++ apps/menu.c (arbetskopia) @@ -322,7 +322,7 @@ while (i < MAX_PATH-1) { int padlen = MIN(len, MAX_PATH-1-i); - strncpy(&padded_title[i], title, padlen); + strlcpy(&padded_title[i], title, padlen); i += padlen; if (ipath, trackname, sizeof(id3->path)); + strlcpy(id3->path, trackname, sizeof(id3->path)); return true; } Index: apps/mpeg.c =================================================================== --- apps/mpeg.c (revision 20590) +++ apps/mpeg.c (arbetskopia) @@ -2209,8 +2209,7 @@ { mpeg_errno = 0; - strncpy(recording_filename, filename, MAX_PATH - 1); - recording_filename[MAX_PATH - 1] = 0; + strlcpy(recording_filename, filename, MAX_PATH); queue_post(&mpeg_queue, MPEG_RECORD, 0); } @@ -2515,8 +2514,7 @@ { mpeg_errno = 0; - strncpy(recording_filename, filename, MAX_PATH - 1); - recording_filename[MAX_PATH - 1] = 0; + strlcpy(recording_filename, filename, MAX_PATH); queue_post(&mpeg_queue, MPEG_NEW_FILE, 0); } Index: apps/talk.c =================================================================== --- apps/talk.c (revision 20590) +++ apps/talk.c (arbetskopia) @@ -534,7 +534,7 @@ #endif /* CONFIG_CODEC == SWCODEC */ talk_initialized = true; - strncpy((char *) last_lang, (char *)global_settings.lang_file, + strlcpy((char *)last_lang, (char *)global_settings.lang_file, MAX_FILENAME); #if CONFIG_CODEC == SWCODEC @@ -756,7 +756,7 @@ } char buf[MAX_PATH]; /* 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] == '/') /* strip trailing slash */ buf[strlen(buf)-1] = '\0'; Index: apps/settings_list.c =================================================================== --- apps/settings_list.c (revision 20590) +++ apps/settings_list.c (arbetskopia) @@ -436,7 +436,7 @@ static char* qs_write_to_cfg(void* setting, char*buf, int buf_len) { const struct settings_list *var = &settings[*(int*)setting]; - strncpy(buf, var->cfg_name, buf_len); + strlcpy(buf, var->cfg_name, buf_len); return buf; } static bool qs_is_changed(void* setting, void* defaultval) Index: apps/tagcache.c =================================================================== --- apps/tagcache.c (revision 20590) +++ apps/tagcache.c (arbetskopia) @@ -738,7 +738,7 @@ if (tag != tag_filename) { ep = (struct tagfile_entry *)&hdr->tags[tag][seek]; - strncpy(buf, ep->tag_data, size-1); + strlcpy(buf, ep->tag_data, size); return true; } Index: apps/playback.c =================================================================== --- apps/playback.c (revision 20590) +++ apps/playback.c (arbetskopia) @@ -602,7 +602,7 @@ return &temp_id3; #endif - strncpy(temp_id3.path, filename, sizeof(temp_id3.path)-1); + strlcpy(temp_id3.path, filename, sizeof(temp_id3.path)); temp_id3.title = strrchr(temp_id3.path, '/'); if (!temp_id3.title) temp_id3.title = &temp_id3.path[0]; Index: apps/replaygain.c =================================================================== --- apps/replaygain.c (revision 20590) +++ apps/replaygain.c (arbetskopia) @@ -395,8 +395,7 @@ /* A few characters just isn't interesting... */ if (len > 1) { - strncpy(buffer, value, len); - buffer[len] = 0; + strlcpy(buffer, value, len + 1); *p = buffer; return len + 1; } Index: apps/plugin.c =================================================================== --- apps/plugin.c (revision 20590) +++ apps/plugin.c (arbetskopia) @@ -372,7 +372,7 @@ snprintf, vsnprintf, strcpy, - strncpy, + strlcpy, strlen, strrchr, strcmp, Index: apps/plugin.h =================================================================== --- apps/plugin.h (revision 20590) +++ apps/plugin.h (arbetskopia) @@ -493,7 +493,7 @@ ATTRIBUTE_PRINTF(3, 4); int (*vsnprintf)(char *buf, int size, const char *fmt, va_list ap); 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); char * (*strrchr)(const char *s, int c); int (*strcmp)(const char *, const char *); Index: apps/bookmark.c =================================================================== --- apps/bookmark.c (revision 20590) +++ apps/bookmark.c (arbetskopia) @@ -1003,17 +1003,14 @@ if (resume_file != NULL) { size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s); - len = MIN(resume_file_size - 1, len); - strncpy(resume_file, s, len); - resume_file[len] = 0; + strlcpy(resume_file, s, len + 1); } if (end != NULL && file_name != NULL) { end++; - strncpy(file_name, end, MAX_PATH - 1); - file_name[MAX_PATH - 1] = 0; + strlcpy(file_name, end, MAX_PATH); } return true; Index: apps/buffering.c =================================================================== --- apps/buffering.c (revision 20590) +++ apps/buffering.c (arbetskopia) @@ -897,7 +897,7 @@ h->widx = buf_widx; h->available = 0; h->type = type; - strncpy(h->path, file, MAX_PATH); + strlcpy(h->path, file, MAX_PATH); buf_widx += sizeof(struct mp3entry); /* safe because the handle can't wrap */ @@ -930,7 +930,7 @@ return ERR_BUFFER_FULL; } - strncpy(h->path, file, MAX_PATH); + strlcpy(h->path, file, MAX_PATH); h->offset = adjusted_offset; h->ridx = buf_widx; h->data = buf_widx; Index: apps/root_menu.c =================================================================== --- apps/root_menu.c (revision 20590) +++ apps/root_menu.c (arbetskopia) @@ -79,7 +79,7 @@ static void rootmenu_track_changed_callback(void* 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) { @@ -204,7 +204,7 @@ #endif case GO_TO_BROWSEPLUGINS: filter = SHOW_PLUGINS; - strncpy(folder, PLUGIN_DIR, MAX_PATH); + strlcpy(folder, PLUGIN_DIR, MAX_PATH); break; } ret_val = rockbox_browse(folder, filter); Index: apps/iap.c =================================================================== --- apps/iap.c (revision 20590) +++ apps/iap.c (arbetskopia) @@ -492,6 +492,7 @@ unsigned char data[70] = {0x04, 0x00, 0xFF}; struct mp3entry id3; int fd; + size_t len; long tracknum = (signed long)serbuf[4] << 24 | (signed long)serbuf[5] << 16 | (signed long)serbuf[6] << 8 | serbuf[7]; @@ -517,16 +518,16 @@ switch(serbuf[3]) { case 0x20: - strncpy((char *)&data[3], id3.title, 64); - iap_send_pkt(data, 4+strlen(id3.title)); + len = strlcpy((char *)&data[3], id3.title, 64); + iap_send_pkt(data, 4+len); break; case 0x22: - strncpy((char *)&data[3], id3.artist, 64); - iap_send_pkt(data, 4+strlen(id3.artist)); + len = strlcpy((char *)&data[3], id3.artist, 64); + iap_send_pkt(data, 4+len); break; case 0x24: - strncpy((char *)&data[3], id3.album, 64); - iap_send_pkt(data, 4+strlen(id3.album)); + len = strlcpy((char *)&data[3], id3.album, 64); + iap_send_pkt(data, 4+len); break; } break; Index: apps/debug_menu.c =================================================================== --- apps/debug_menu.c (revision 20590) +++ apps/debug_menu.c (arbetskopia) @@ -1900,8 +1900,7 @@ if (card->initialized > 0) { - card_name[6] = '\0'; - strncpy(card_name, ((unsigned char*)card->cid) + 3, 6); + strlcpy(card_name, ((unsigned char*)card->cid) + 3, sizeof(card_name)); simplelist_addline(SIMPLELIST_ADD_LINE, "%s Rev %d.%d", card_name, (int) card_extract_bits(card->cid, 72, 4), Index: apps/misc.c =================================================================== --- apps/misc.c (revision 20590) +++ apps/misc.c (arbetskopia) @@ -814,15 +814,13 @@ { len = dot - filename; len = MIN(len, buffer_size); - strncpy(buffer, filename, len); } else { len = buffer_size; - strncpy(buffer, filename, buffer_size); } - buffer[len] = 0; + strlcpy(buffer, filename, len + 1); return buffer; } Index: apps/playlist_catalog.c =================================================================== --- apps/playlist_catalog.c (revision 20590) +++ apps/playlist_catalog.c (arbetskopia) @@ -79,7 +79,7 @@ /* fall back to default directory if no or invalid config */ if (default_dir) - strncpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR, + strlcpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR, sizeof(playlist_dir)); playlist_dir_length = strlen(playlist_dir); @@ -190,7 +190,7 @@ { 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 || (global_settings.show_filename_ext == 3 @@ -479,7 +479,7 @@ 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)); return true; } Index: apps/tagtree.c =================================================================== --- apps/tagtree.c (revision 20590) +++ apps/tagtree.c (arbetskopia) @@ -585,7 +585,7 @@ menus[menu_count] = buffer_alloc(sizeof(struct root_menu)); new_menu = menus[menu_count]; memset(new_menu, 0, sizeof(struct root_menu)); - strncpy(new_menu->id, buf, MAX_MENU_ID_SIZE-1); + strlcpy(new_menu->id, buf, MAX_MENU_ID_SIZE); entry->link = menu_count; ++menu_count; @@ -827,7 +827,7 @@ menu = menus[menu_count]; ++menu_count; memset(menu, 0, sizeof(struct root_menu)); - 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) @@ -1428,8 +1428,8 @@ csi = menu->items[seek]->si; c->currextra = 0; - strncpy(current_title[c->currextra], dptr->name, - sizeof(current_title[0]) - 1); + strlcpy(current_title[c->currextra], dptr->name, + sizeof(current_title[0])); /* Read input as necessary. */ for (i = 0; i < csi->tagorder_count; i++) @@ -1450,7 +1450,7 @@ if (source == source_current_path && id3) { char *e; - strncpy(searchstring, id3->path, SEARCHSTR_SIZE); + strlcpy(searchstring, id3->path, SEARCHSTR_SIZE); e = strrchr(searchstring, '/'); if (e) *e = '\0'; @@ -1463,8 +1463,7 @@ char **src = (char**)((char*)id3 + offset); if (*src) { - strncpy(searchstring, *src, SEARCHSTR_SIZE); - searchstring[SEARCHSTR_SIZE-1] = '\0'; + strlcpy(searchstring, *src, SEARCHSTR_SIZE); } } else @@ -1514,8 +1513,8 @@ c->dirlevel--; /* Update the statusbar title */ - strncpy(current_title[c->currextra], dptr->name, - sizeof(current_title[0]) - 1); + strlcpy(current_title[c->currextra], dptr->name, + sizeof(current_title[0])); break; default: Index: firmware/general.c =================================================================== --- firmware/general.c (revision 20590) +++ firmware/general.c (arbetskopia) @@ -109,7 +109,7 @@ char fmtstring[12]; if (buffer != path) - strncpy(buffer, path, MAX_PATH); + strlcpy(buffer, path, MAX_PATH); pathlen = strlen(buffer); @@ -180,7 +180,7 @@ last_tm = *tm; if (buffer != path) - strncpy(buffer, path, MAX_PATH); + strlcpy(buffer, path, MAX_PATH); pathlen = strlen(buffer); snprintf(buffer + pathlen, MAX_PATH - pathlen, Index: firmware/logf.c =================================================================== --- firmware/logf.c (revision 20590) +++ firmware/logf.c (arbetskopia) @@ -145,7 +145,7 @@ while(len > MAX_LOGF_ENTRY) { 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; logfindex++; check_logfindex(); Index: firmware/include/string.h =================================================================== --- firmware/include/string.h (revision 20590) +++ firmware/include/string.h (arbetskopia) @@ -35,13 +35,14 @@ size_t _EXFUN(strlen,(const char *)); char *_EXFUN(strncat,(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(strrchr,(const char *, int)); size_t _EXFUN(strspn,(const char *, const char *)); char *_EXFUN(strstr,(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 char *_EXFUN(strtok,(char *, const char *)); #endif Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (revision 20590) +++ firmware/SOURCES (arbetskopia) @@ -52,7 +52,7 @@ common/strnatcmp.c common/strcpy.c common/strncmp.c -common/strncpy.c +common/strlcpy.c common/strrchr.c common/strtok.c common/strstr.c Index: firmware/common/strlcpy.c =================================================================== --- firmware/common/strlcpy.c (revision 0) +++ firmware/common/strlcpy.c (revision 0) @@ -0,0 +1,51 @@ +/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * + * 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 +#include + +/* + * 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 */ +} Egenskapsändringar för: firmware/common/strlcpy.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Index: firmware/common/dircache.c =================================================================== --- firmware/common/dircache.c (revision 20590) +++ firmware/common/dircache.c (arbetskopia) @@ -232,11 +232,11 @@ return -2; td->pathpos = strlen(dircache_cur_path); - strncpy(&dircache_cur_path[td->pathpos], "/", + strlcpy(&dircache_cur_path[td->pathpos], "/", + sizeof(dircache_cur_path) - td->pathpos); +#ifdef SIMULATOR + strlcpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, sizeof(dircache_cur_path) - td->pathpos - 1); -#ifdef SIMULATOR - strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, - sizeof(dircache_cur_path) - td->pathpos - 2); td->newdir = opendir_uncached(dircache_cur_path); if (td->newdir == NULL) @@ -245,8 +245,8 @@ return -3; } #else - strncpy(&dircache_cur_path[td->pathpos+1], td->entry.name, - sizeof(dircache_cur_path) - td->pathpos - 2); + strlcpy(&dircache_cur_path[td->pathpos+1], td->entry.name, + sizeof(dircache_cur_path) - td->pathpos - 1); td->newdir = *td->dir; if (fat_opendir(IF_MV2(volume,) &td->newdir, @@ -399,7 +399,7 @@ char* part; char* end; - strncpy(namecopy, path, sizeof(namecopy) - 1); + strlcpy(namecopy, path, sizeof(namecopy)); cache_entry = dircache_root; before = NULL; @@ -926,7 +926,7 @@ char *new; long last_cache_size = dircache_size; - strncpy(basedir, path, sizeof(basedir)-1); + strlcpy(basedir, path, sizeof(basedir)); new = strrchr(basedir, '/'); if (new == NULL) { @@ -997,8 +997,8 @@ { if (fdbind_idx >= MAX_PENDING_BINDINGS) return ; - strncpy(fdbind_cache[fdbind_idx].path, path, - sizeof(fdbind_cache[fdbind_idx].path)-1); + strlcpy(fdbind_cache[fdbind_idx].path, path, + sizeof(fdbind_cache[fdbind_idx].path)); fdbind_cache[fdbind_idx].fd = fd; fdbind_idx++; return ; @@ -1141,7 +1141,7 @@ /* Generate the absolute path for destination if necessary. */ if (newpath[0] != '/') { - strncpy(absolute_path, oldpath, sizeof(absolute_path)-1); + strlcpy(absolute_path, oldpath, sizeof(absolute_path)); p = strrchr(absolute_path, '/'); if (!p) { @@ -1151,7 +1151,7 @@ } *p = '\0'; - strncpy(p, absolute_path, sizeof(absolute_path)-1-strlen(p)); + strlcpy(p, absolute_path, sizeof(absolute_path)-strlen(p)); newpath = absolute_path; } @@ -1246,7 +1246,7 @@ if (regentry == 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.startcluster = regentry->startcluster; dir->secondary_entry.attribute = regentry->attribute; @@ -1268,7 +1268,7 @@ 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` because that modifies the d_name pointer. */ dir->secondary_entry.size = ce->size; Index: firmware/common/strncpy.c =================================================================== --- firmware/common/strncpy.c (revision 20590) +++ firmware/common/strncpy.c (arbetskopia) @@ -1,125 +0,0 @@ -/* -FUNCTION - <>---counted copy string - -INDEX - strncpy - -ANSI_SYNOPSIS - #include - char *strncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - char *strncpy(<[dst]>, <[src]>, <[length]>) - char *<[dst]>; - char *<[src]>; - size_t <[length]>; - -DESCRIPTION - <> copies not more than <[length]> characters from the - the string pointed to by <[src]> (including the terminating - null character) to the array pointed to by <[dst]>. If the - string pointed to by <[src]> is shorter than <[length]> - characters, null characters are appended to the destination - array until a total of <[length]> characters have been - written. - -RETURNS - This function returns the initial value of <[dst]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strncpy ansi pure -*/ - -#include -#include - -/*SUPPRESS 560*/ -/*SUPPRESS 530*/ - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -#define TOO_SMALL(LEN) ((LEN) < sizeof (long)) - -char * -_DEFUN (strncpy, (dst0, src0), - char *dst0 _AND - _CONST char *src0 _AND - size_t count) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *dscan; - _CONST char *sscan; - - dscan = dst0; - sscan = src0; - while (count > 0) - { - --count; - if ((*dscan++ = *sscan++) == '\0') - break; - } - while (count-- > 0) - *dscan++ = '\0'; - - return dst0; -#else - char *dst = dst0; - _CONST char *src = src0; - long *aligned_dst; - _CONST long *aligned_src; - - /* If SRC and DEST is aligned and count large enough, then copy words. */ - if (!UNALIGNED (src, dst) && !TOO_SMALL (count)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* SRC and DEST are both "long int" aligned, try to do "long int" - sized copies. */ - while (count >= sizeof (long int) && !DETECTNULL(*aligned_src)) - { - count -= sizeof (long int); - *aligned_dst++ = *aligned_src++; - } - - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while (count > 0) - { - --count; - if ((*dst++ = *src++) == '\0') - break; - } - - while (count-- > 0) - *dst++ = '\0'; - - return dst0; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} Index: firmware/common/dir_uncached.c =================================================================== --- firmware/common/dir_uncached.c (revision 20590) +++ firmware/common/dir_uncached.c (arbetskopia) @@ -58,8 +58,7 @@ name = "/"; /* else this must be the root dir */ } - strncpy(namecopy, name, MAX_PATH); - namecopy[MAX_PATH-1] = '\0'; + strlcpy(namecopy, name, MAX_PATH); return volume; } @@ -120,8 +119,7 @@ volume = strip_volume(name, namecopy); pdir->volumecounter = 0; #else - strncpy(namecopy,name,sizeof(namecopy)); /* just copy */ - namecopy[sizeof(namecopy)-1] = '\0'; + strlcpy(namecopy, name, sizeof(namecopy)); /* just copy */ #endif if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) { @@ -204,7 +202,7 @@ if ( !entry.name[0] ) 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->size = entry.filesize; theent->startcluster = entry.firstcluster; @@ -230,8 +228,7 @@ return -1; } - strncpy(namecopy,name,sizeof(namecopy)); - namecopy[sizeof(namecopy)-1] = 0; + strlcpy(namecopy, name, sizeof(namecopy)); /* Split the base name and the path */ end = strrchr(namecopy, '/'); Index: firmware/common/file.c =================================================================== --- firmware/common/file.c (revision 20590) +++ firmware/common/file.c (arbetskopia) @@ -132,8 +132,7 @@ } #endif - strncpy(pathnamecopy,pathname,sizeof(pathnamecopy)); - pathnamecopy[sizeof(pathnamecopy)-1] = 0; + strlcpy(pathnamecopy, pathname, sizeof(pathnamecopy)); /* locate filename */ name=strrchr(pathnamecopy+1,'/'); Index: firmware/drivers/lcd-charcell.c =================================================================== --- firmware/drivers/lcd-charcell.c (revision 20590) +++ firmware/drivers/lcd-charcell.c (arbetskopia) @@ -496,7 +496,7 @@ } 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->y = y; Index: firmware/drivers/lcd-1bit-vert.c =================================================================== --- firmware/drivers/lcd-1bit-vert.c (revision 20590) +++ firmware/drivers/lcd-1bit-vert.c (arbetskopia) @@ -845,7 +845,7 @@ } end = strchr(s->line, '\0'); - strncpy(end, string, current_vp->width/2); + strlcpy(end, string, current_vp->width/2); s->vp = current_vp; s->y = y; Index: firmware/drivers/lcd-2bit-vert.c =================================================================== --- firmware/drivers/lcd-2bit-vert.c (revision 20590) +++ firmware/drivers/lcd-2bit-vert.c (arbetskopia) @@ -1152,7 +1152,7 @@ } 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->y = y; Index: firmware/drivers/fat.c =================================================================== --- firmware/drivers/fat.c (revision 20590) +++ firmware/drivers/fat.c (arbetskopia) @@ -1183,7 +1183,7 @@ /* shortname entry */ unsigned short date=0, time=0, tenth=0; LDEBUGF("Shortname entry: %s\n", shortname); - strncpy(entry + FATDIR_NAME, shortname, 11); + strlcpy(entry + FATDIR_NAME, shortname, 11); entry[FATDIR_ATTR] = is_directory?FAT_ATTR_DIRECTORY:0; entry[FATDIR_NTRES] = 0; @@ -1271,7 +1271,7 @@ /* The "." and ".." directory entries must not be long names */ if(dotdir) { int i; - strncpy(shortname, name, 12); + strlcpy(shortname, name, 12); for(i = strlen(shortname); i < 12; i++) shortname[i] = ' '; Index: firmware/drivers/lcd-2bit-vi.c =================================================================== --- firmware/drivers/lcd-2bit-vi.c (revision 20590) +++ firmware/drivers/lcd-2bit-vi.c (arbetskopia) @@ -1167,7 +1167,7 @@ } 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->y = y; Index: firmware/drivers/lcd-16bit.c =================================================================== --- firmware/drivers/lcd-16bit.c (revision 20590) +++ firmware/drivers/lcd-16bit.c (arbetskopia) @@ -1153,7 +1153,7 @@ } end = strchr(s->line, '\0'); - strncpy(end, string, current_vp->width/2); + strlcpy(end, string, current_vp->width/2); s->vp = current_vp; s->y = y;