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:
14
trace.c
14
trace.c
@ -191,15 +191,11 @@ static int strrepc(char *pszStr, char cFrom, char cTo)
|
||||
|
||||
/*----------------------------------------------------------------*/
|
||||
|
||||
while( 0 != ( ptr = strchr( pszStr, cFrom ) ) )
|
||||
|
||||
{ /* WHILE cFrom occurs in pszStr */
|
||||
|
||||
pszStr[ (int) ptr - (int) pszStr ] = cTo ;
|
||||
|
||||
/*- Replace next cFrom with cTo */
|
||||
|
||||
iReturn++ ; /*- count */
|
||||
for (ptr = pszStr; ptr && *ptr; ++ptr) {
|
||||
if (*ptr == cFrom) {
|
||||
*ptr = cTo;
|
||||
++iReturn;
|
||||
}
|
||||
}
|
||||
|
||||
return( iReturn ) ;
|
||||
|
Reference in New Issue
Block a user