Clean up use of snprintf where strncpy if suited, avoid useless copying of constant strings for wps token evaluator, minor const police too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18625 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
7d4cebd7da
commit
93a87685c3
8 changed files with 37 additions and 47 deletions
|
@ -272,8 +272,7 @@ static char *list_get_name_cb(int selected_item,
|
|||
struct cuesheet *cue = (struct cuesheet *)data;
|
||||
|
||||
if (selected_item & 1)
|
||||
snprintf(buffer, buffer_len, "%s",
|
||||
cue->tracks[selected_item/2].title);
|
||||
strncpy(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);
|
||||
|
|
|
@ -771,10 +771,10 @@ static char* get_dir(char* buf, int buf_size, const char* path, int level)
|
|||
and the original value of *intval, inclusive).
|
||||
When not treating a conditional/enum, intval should be NULL.
|
||||
*/
|
||||
static char *get_token_value(struct gui_wps *gwps,
|
||||
struct wps_token *token,
|
||||
char *buf, int buf_size,
|
||||
int *intval)
|
||||
static const char *get_token_value(struct gui_wps *gwps,
|
||||
struct wps_token *token,
|
||||
char *buf, int buf_size,
|
||||
int *intval)
|
||||
{
|
||||
if (!gwps)
|
||||
return NULL;
|
||||
|
@ -978,8 +978,7 @@ static char *get_token_value(struct gui_wps *gwps,
|
|||
|
||||
case WPS_TOKEN_ALBUMART_FOUND:
|
||||
if (audio_current_aa_hid() >= 0) {
|
||||
snprintf(buf, buf_size, "C");
|
||||
return buf;
|
||||
return "C";
|
||||
}
|
||||
return NULL;
|
||||
#endif
|
||||
|
@ -988,7 +987,7 @@ static char *get_token_value(struct gui_wps *gwps,
|
|||
if(id3->bitrate)
|
||||
snprintf(buf, buf_size, "%d", id3->bitrate);
|
||||
else
|
||||
snprintf(buf, buf_size, "?");
|
||||
return "?";
|
||||
return buf;
|
||||
|
||||
case WPS_TOKEN_FILE_CODEC:
|
||||
|
@ -1080,7 +1079,7 @@ static char *get_token_value(struct gui_wps *gwps,
|
|||
if (t >= 0)
|
||||
snprintf(buf, buf_size, "%dh %dm", t / 60, t % 60);
|
||||
else
|
||||
strncpy(buf, "?h ?m", buf_size);
|
||||
return "?h ?m";
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -1208,23 +1207,19 @@ static char *get_token_value(struct gui_wps *gwps,
|
|||
|
||||
case WPS_TOKEN_RTC_AM_PM_UPPER:
|
||||
/* p: upper case AM or PM indicator */
|
||||
snprintf(buf, buf_size, (tm->tm_hour/12 == 0) ? "AM" : "PM");
|
||||
return buf;
|
||||
return tm->tm_hour/12 == 0 ? "AM" : "PM";
|
||||
|
||||
case WPS_TOKEN_RTC_AM_PM_LOWER:
|
||||
/* P: lower case am or pm indicator */
|
||||
snprintf(buf, buf_size, (tm->tm_hour/12 == 0) ? "am" : "pm");
|
||||
return buf;
|
||||
return tm->tm_hour/12 == 0 ? "am" : "pm";
|
||||
|
||||
case WPS_TOKEN_RTC_WEEKDAY_NAME:
|
||||
/* a: abbreviated weekday name (Sun..Sat) */
|
||||
snprintf(buf, buf_size, "%s",str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
|
||||
return buf;
|
||||
return str(LANG_WEEKDAY_SUNDAY + tm->tm_wday);
|
||||
|
||||
case WPS_TOKEN_RTC_MONTH_NAME:
|
||||
/* b: abbreviated month name (Jan..Dec) */
|
||||
snprintf(buf, buf_size, "%s",str(LANG_MONTH_JANUARY + tm->tm_mon));
|
||||
return buf;
|
||||
return str(LANG_MONTH_JANUARY + tm->tm_mon);
|
||||
|
||||
case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
|
||||
/* u: day of week (1..7); 1 is Monday */
|
||||
|
@ -1252,19 +1247,15 @@ static char *get_token_value(struct gui_wps *gwps,
|
|||
case WPS_TOKEN_RTC_AM_PM_UPPER:
|
||||
case WPS_TOKEN_RTC_AM_PM_LOWER:
|
||||
case WPS_TOKEN_RTC_YEAR_2_DIGITS:
|
||||
strncpy(buf, "--", buf_size);
|
||||
return buf;
|
||||
return "--";
|
||||
case WPS_TOKEN_RTC_YEAR_4_DIGITS:
|
||||
strncpy(buf, "----", buf_size);
|
||||
return buf;
|
||||
return "----";
|
||||
case WPS_TOKEN_RTC_WEEKDAY_NAME:
|
||||
case WPS_TOKEN_RTC_MONTH_NAME:
|
||||
strncpy(buf, "---", buf_size);
|
||||
return buf;
|
||||
return "---";
|
||||
case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
|
||||
case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
|
||||
strncpy(buf, "-", buf_size);
|
||||
return buf;
|
||||
return "-";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LCD_CHARCELLS
|
||||
|
@ -1280,12 +1271,12 @@ static char *get_token_value(struct gui_wps *gwps,
|
|||
{
|
||||
/* we need 11 characters (full line) for
|
||||
progress-bar */
|
||||
snprintf(buf, buf_size, " ");
|
||||
strncpy(buf, " ", buf_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Tell the user if we have an OldPlayer */
|
||||
snprintf(buf, buf_size, " <Old LCD> ");
|
||||
strncpy(buf, " <Old LCD> ", buf_size);
|
||||
}
|
||||
return buf;
|
||||
#endif
|
||||
|
@ -1428,7 +1419,8 @@ static bool evaluate_conditional(struct gui_wps *gwps, int *token_index)
|
|||
|
||||
int i, cond_end;
|
||||
int cond_index = *token_index;
|
||||
char result[128], *value;
|
||||
char result[128];
|
||||
const char *value;
|
||||
unsigned char num_options = data->tokens[cond_index].value.i & 0xFF;
|
||||
unsigned char prev_val = (data->tokens[cond_index].value.i & 0xFF00) >> 8;
|
||||
|
||||
|
@ -1598,7 +1590,7 @@ static bool get_line(struct gui_wps *gwps,
|
|||
default:
|
||||
{
|
||||
/* get the value of the tag and copy it to the buffer */
|
||||
char *value = get_token_value(gwps, &data->tokens[i],
|
||||
const char *value = get_token_value(gwps, &data->tokens[i],
|
||||
temp_buf, sizeof(temp_buf), NULL);
|
||||
if (value)
|
||||
{
|
||||
|
|
|
@ -78,9 +78,8 @@ char *option_get_valuestring(const struct settings_list *setting,
|
|||
if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
|
||||
{
|
||||
bool val = (bool)temp_var;
|
||||
snprintf(buffer, buf_len, "%s",
|
||||
str(val? setting->bool_setting->lang_yes :
|
||||
setting->bool_setting->lang_no));
|
||||
strncpy(buffer, str(val? setting->bool_setting->lang_yes :
|
||||
setting->bool_setting->lang_no), buf_len);
|
||||
}
|
||||
#if 0 /* probably dont need this one */
|
||||
else if ((setting->flags & F_FILENAME) == F_FILENAME)
|
||||
|
@ -140,7 +139,7 @@ char *option_get_valuestring(const struct settings_list *setting,
|
|||
const struct choice_setting *info = setting->choice_setting;
|
||||
if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY)
|
||||
{
|
||||
snprintf(buffer, buf_len, "%s", str(info->talks[(int)temp_var]));
|
||||
strncpy(buffer, str(info->talks[(int)temp_var]), buf_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -152,7 +151,7 @@ char *option_get_valuestring(const struct settings_list *setting,
|
|||
{
|
||||
int value= (int)temp_var;
|
||||
char *val = P2STR(setting->choice_setting->desc[value]);
|
||||
snprintf(buffer, buf_len, "%s", val);
|
||||
strncpy(buffer, val, buf_len);
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
|
|
|
@ -741,15 +741,15 @@ static void gui_statusbar_icon_recording_info(struct screen * display)
|
|||
if (global_settings.rec_source == AUDIO_SRC_SPDIF)
|
||||
{
|
||||
/* Can't measure S/PDIF sample rate on Archos/Sim yet */
|
||||
snprintf(buffer, sizeof(buffer), "--");
|
||||
strncpy(buffer, "--", sizeof(buffer));
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_SPDIF_IN */
|
||||
{
|
||||
static char const * const freq_strings[12] =
|
||||
{ "44", "48", "32", "22", "24", "16" };
|
||||
snprintf(buffer, sizeof(buffer), "%s",
|
||||
freq_strings[global_settings.rec_frequency]);
|
||||
strncpy(buffer, freq_strings[global_settings.rec_frequency],
|
||||
sizeof(buffer));
|
||||
}
|
||||
|
||||
display->getstringsize(buffer, &width, &height);
|
||||
|
|
|
@ -204,7 +204,7 @@ static char* info_getname(int selected_item, void *data,
|
|||
}
|
||||
else
|
||||
{
|
||||
snprintf(buffer, buffer_len, "%s", "--:--:--");
|
||||
strncpy(buffer, "--:--:--", buffer_len);
|
||||
}
|
||||
break;
|
||||
case INFO_DATE:
|
||||
|
@ -218,7 +218,7 @@ static char* info_getname(int selected_item, void *data,
|
|||
}
|
||||
else
|
||||
{
|
||||
snprintf(buffer, buffer_len, "%s", str(LANG_UNKNOWN));
|
||||
strncpy(buffer, str(LANG_UNKNOWN), buffer_len);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
@ -492,7 +492,7 @@ static void sleep_timer_formatter(char* buffer, size_t buffer_size, int value,
|
|||
minutes = value - (hours * 60);
|
||||
snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
|
||||
} else {
|
||||
snprintf(buffer, buffer_size, "%s", str(LANG_OFF));
|
||||
strncpy(buffer, str(LANG_OFF), buffer_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1894,8 +1894,8 @@ void playlist_init(void)
|
|||
struct playlist_info* playlist = ¤t_playlist;
|
||||
|
||||
playlist->current = true;
|
||||
snprintf(playlist->control_filename, sizeof(playlist->control_filename),
|
||||
"%s", PLAYLIST_CONTROL_FILE);
|
||||
strncpy(playlist->control_filename, PLAYLIST_CONTROL_FILE,
|
||||
sizeof(playlist->control_filename));
|
||||
playlist->fd = -1;
|
||||
playlist->control_fd = -1;
|
||||
playlist->max_playlist_size = global_settings.max_files_in_playlist;
|
||||
|
@ -3230,7 +3230,7 @@ char *playlist_name(const struct playlist_info* playlist, char *buf,
|
|||
if (!playlist)
|
||||
playlist = ¤t_playlist;
|
||||
|
||||
snprintf(buf, buf_size, "%s", playlist->filename+playlist->dirlen);
|
||||
strncpy(buf, playlist->filename+playlist->dirlen, buf_size);
|
||||
|
||||
if (!buf[0])
|
||||
return NULL;
|
||||
|
@ -3250,7 +3250,7 @@ char *playlist_get_name(const struct playlist_info* playlist, char *buf,
|
|||
if (!playlist)
|
||||
playlist = ¤t_playlist;
|
||||
|
||||
snprintf(buf, buf_size, "%s", playlist->filename);
|
||||
strncpy(buf, playlist->filename, buf_size);
|
||||
|
||||
if (!buf[0])
|
||||
return NULL;
|
||||
|
|
|
@ -198,7 +198,7 @@ static int browser(void* param)
|
|||
#endif
|
||||
case GO_TO_BROWSEPLUGINS:
|
||||
filter = SHOW_PLUGINS;
|
||||
snprintf(folder, MAX_PATH, "%s", PLUGIN_DIR);
|
||||
strncpy(folder, PLUGIN_DIR, MAX_PATH);
|
||||
break;
|
||||
}
|
||||
ret_val = rockbox_browse(folder, filter);
|
||||
|
|
|
@ -1067,7 +1067,7 @@ static void set_option_formatter(char* buf, size_t size, int item, const char* u
|
|||
{
|
||||
(void)unit;
|
||||
const unsigned char *text = set_option_options[item].string;
|
||||
snprintf(buf, size, "%s", P2STR(text));
|
||||
strncpy(buf, P2STR(text), size);
|
||||
}
|
||||
static int32_t set_option_get_talk_id(int value, int unit)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue