Correct detection of the absence of the current preset
authoralle <alle@a1c6a512-1295-4272-9138-f99709370657>
Thu, 13 May 2010 08:36:38 +0000 (13 08:36 +0000)
committeralle <alle@a1c6a512-1295-4272-9138-f99709370657>
Thu, 13 May 2010 08:36:38 +0000 (13 08:36 +0000)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25990 a1c6a512-1295-4272-9138-f99709370657

apps/gui/skin_engine/skin_tokens.c

index 165c3b9..b9d4bd6 100644 (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);