# HG changeset patch # User ib # Date 1299766836 0 # Node ID 4905f5a8735717223a0020c087456999bd02f3a4 # Parent b68d209b6f285129499c95a2a5d87b53cc414156 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. diff -r b68d209b6f28 -r 4905f5a87357 gui/mplayer/gui_common.c --- a/gui/mplayer/gui_common.c Thu Mar 10 13:22:11 2011 +0000 +++ b/gui/mplayer/gui_common.c Thu Mar 10 14:20:36 2011 +0000 @@ -91,7 +91,7 @@ } if (c) { - for (i = 0; i < (int)strlen(tmp); i++) { + for (i = 0; tmp[i]; i++) { int t = 0; if (c == 1) diff -r b68d209b6f28 -r 4905f5a87357 gui/skin/cut.c --- a/gui/skin/cut.c Thu Mar 10 13:22:11 2011 +0000 +++ b/gui/skin/cut.c Thu Mar 10 14:20:36 2011 +0000 @@ -26,7 +26,7 @@ int n; unsigned int i, c; - for (c = 0, n = 0, i = 0; i < strlen(in); i++) { + for (c = 0, n = 0, i = 0; in[i]; i++) { if (in[i] == sep) n++; if (n >= num && in[i] != sep && c + 1 < maxout) diff -r b68d209b6f28 -r 4905f5a87357 gui/skin/skin.c --- 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)) {