Fix some weird code in strrepc of task.c

So little code, so many faults:
* It calls strchr from the beginning each time
  (it could use ++ptr as the start)
* If cFrom and cTo are the same it loops forever
* if int is 32bits && ptr is 64bits it may break
  (many are, and the cast truncates the pointer)
* if sizeof(char) > 1 it breaks badly
This commit is contained in:
Douglas Clowes
2015-07-24 13:50:26 +10:00
parent 8a91653f13
commit f0021db2ff

14
trace.c
View File

@ -191,15 +191,11 @@ static int strrepc(char *pszStr, char cFrom, char cTo)
/*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/
while( 0 != ( ptr = strchr( pszStr, cFrom ) ) ) for (ptr = pszStr; ptr && *ptr; ++ptr) {
if (*ptr == cFrom) {
{ /* WHILE cFrom occurs in pszStr */ *ptr = cTo;
++iReturn;
pszStr[ (int) ptr - (int) pszStr ] = cTo ; }
/*- Replace next cFrom with cTo */
iReturn++ ; /*- count */
} }
return( iReturn ) ; return( iReturn ) ;