1
0
Fork 0
forked from len0rd/rockbox

Correct detection of the absence of the current preset

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25990 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Alexander Levin 2010-05-13 08:36:38 +00:00
parent cd8ed00dfe
commit 230f0405eb

View file

@ -398,13 +398,15 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
case WPS_TOKEN_PRESET_NAME:
case WPS_TOKEN_PRESET_FREQ:
{
int preset = radio_current_preset() + preset_offset;
if (radio_preset_count() == 0 || preset == -1)
int preset_count = radio_preset_count();
int cur_preset = radio_current_preset();
if (preset_count == 0 || cur_preset < 0)
return NULL;
/* make sure its in the valid range */
int preset = cur_preset + preset_offset;
/* make sure it's in the valid range */
while (preset < 0)
preset += radio_preset_count();
preset %= radio_preset_count();
preset += preset_count;
preset %= preset_count;
if (token->type == WPS_TOKEN_PRESET_NAME)
{
snprintf(buf, buf_size, "%s", radio_get_preset(preset)->name);