diff gui/skin/skin.c @ 32979:4905f5a87357

Replace some awkward and unnecessary usages of strlen(). 1. A string length of zero or greater than zero can be determined by checking the first byte. 2. Leave it to strdup() to determine the length and to do allocation for a string that is to be copied. 3. If neither the string length nor the index variable is altered in a loop, string[index] (!= 0) is the condition to go with.
author ib
date Thu, 10 Mar 2011 14:20:36 +0000
parents 80087dd00035
children 2bfd000bb789
line wrap: on
line diff
--- a/gui/skin/skin.c	Thu Mar 10 13:22:11 2011 +0000
+++ b/gui/skin/skin.c	Thu Mar 10 14:20:36 2011 +0000
@@ -179,7 +179,7 @@
 
     mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin]  %send (%s)\n", space, name);
 
-    if (strlen(window_name)) {
+    if (window_name[0]) {
         window_name[0] = 0;
         currSection    = NULL;
         currSubItem    = NULL;
@@ -711,14 +711,13 @@
     item->y      = y;
     item->width  = -1;
     item->height = -1;
+    item->label  = strdup(tmp);
 
-    if ((item->label = malloc(strlen(tmp) + 1)) == NULL) {
+    if (!item->label) {
         ERRORMESSAGE(MSGTR_SKIN_FONT_NotEnoughtMemory);
         return 1;
     }
 
-    strcpy(item->label, tmp);
-
     return 0;
 }
 
@@ -766,14 +765,13 @@
     item->y      = y;
     item->width  = sx;
     item->height = -1;
+    item->label  = strdup(tmp);
 
-    if ((item->label = malloc(strlen(tmp) + 1)) == NULL) {
+    if (!item->label) {
         ERRORMESSAGE(MSGTR_SKIN_FONT_NotEnoughtMemory);
         return 1;
     }
 
-    strcpy(item->label, tmp);
-
     return 0;
 }
 
@@ -829,10 +827,10 @@
 {
     int i;
 
-    if (strlen(in) == 0)
+    if (!*in)
         return NULL;
 
-    for (i = 0; i < (int)strlen(in); i++)
+    for (i = 0; in[i]; i++)
         if (in[i] == what)
             in[i] = whereof;
 
@@ -843,7 +841,7 @@
 {
     int c = 0, id = 0, i;
 
-    if (strlen(in) == 0)
+    if (!*in)
         return NULL;
 
     while (c != (int)strlen(in)) {