From 389db1f113cbc0f81f2a7311fa4114c749c81595 Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Sun, 25 Sep 2005 16:15:17 +0200 Subject: [PATCH] Fix strswab() to reliably find end of string Patch by Andrew Dyer, 08 Feb 2005 --- CHANGELOG | 3 +++ lib_generic/string.c | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cef4f8c24f..a00213d08a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,9 @@ Changes for U-Boot 1.1.4: ====================================================================== +* Fix strswab() to reliably find end of string + Patch by Andrew Dyer, 08 Feb 2005 + * Fix typos in include/ppc440.h Patch by Andrew E Mileski, 04 Feb 2005 diff --git a/lib_generic/string.c b/lib_generic/string.c index 5ba8d7cb51..dea4d69a9b 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; -- 2.39.5