summaryrefslogtreecommitdiff
path: root/lib_generic
diff options
context:
space:
mode:
authorWolfgang Denk <wd@pollux.(none)>2005-09-25 16:15:17 +0200
committerWolfgang Denk <wd@pollux.(none)>2005-09-25 16:15:17 +0200
commit389db1f113cbc0f81f2a7311fa4114c749c81595 (patch)
treed99eb49d2b08633b5cd2b65f58ba7cd020453470 /lib_generic
parent6ed6ce62bec68d491efde5a7b36a4366b586baa8 (diff)
Fix strswab() to reliably find end of string
Patch by Andrew Dyer, 08 Feb 2005
Diffstat (limited to 'lib_generic')
-rw-r--r--lib_generic/string.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib_generic/string.c b/lib_generic/string.c
index 5ba8d7cb514..dea4d69a9b3 100644
--- a/lib_generic/string.c
+++ b/lib_generic/string.c
@@ -374,17 +374,18 @@ char * strsep(char **s, const char *ct)
*/
char *strswab(const char *s)
{
- char *p;
+ char *p, *q;
if ((NULL == s) || ('\0' == *s)) {
return (NULL);
}
- for (p = ((char *)s + 1); '\0' != *p; p += 2) {
+ for (p=(char *)s, q=p+1; (*p != '\0') && (*p != '\0'); p+=2, q+=2) {
char tmp;
- tmp = *(p-1);
- *(p-1) = *p;
- *p = tmp;
+
+ tmp = *p;
+ *p = *q;
+ *q = tmp;
}
return (char *) s;