Commit 389db1f113cbc0f81f2a7311fa4114c749c81595

Authored by Wolfgang Denk
1 parent 6ed6ce62be

Fix strswab() to reliably find end of string

Patch by Andrew Dyer, 08 Feb 2005

Showing 2 changed files with 9 additions and 5 deletions Side-by-side Diff

... ... @@ -2,6 +2,9 @@
2 2 Changes for U-Boot 1.1.4:
3 3 ======================================================================
4 4  
  5 +* Fix strswab() to reliably find end of string
  6 + Patch by Andrew Dyer, 08 Feb 2005
  7 +
5 8 * Fix typos in include/ppc440.h
6 9 Patch by Andrew E Mileski, 04 Feb 2005
7 10  
lib_generic/string.c
... ... @@ -374,17 +374,18 @@
374 374 */
375 375 char *strswab(const char *s)
376 376 {
377   - char *p;
  377 + char *p, *q;
378 378  
379 379 if ((NULL == s) || ('\0' == *s)) {
380 380 return (NULL);
381 381 }
382 382  
383   - for (p = ((char *)s + 1); '\0' != *p; p += 2) {
  383 + for (p=(char *)s, q=p+1; (*p != '\0') && (*p != '\0'); p+=2, q+=2) {
384 384 char tmp;
385   - tmp = *(p-1);
386   - *(p-1) = *p;
387   - *p = tmp;
  385 +
  386 + tmp = *p;
  387 + *p = *q;
  388 + *q = tmp;
388 389 }
389 390  
390 391 return (char *) s;