mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
string: avoid undefined behavior in strrchr()
The pre-decrement would not only cause misbehavior when wrapping (benign because there shouldn't be any NULL pointers passed in), but may also create a pointer pointing outside the object that the passed in pointer points to (it won't be de-referenced though). Take the opportunity and also - convert bogus space (partly 7 of them) indentation to Linux style tab one, - add two blank lines. Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Juergen Gross <jgross@suse.com> Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
1 parent
fa6eba8d35
commit
592b5fcb98
1 file changed
+7
-6
+7
-6
@@ -174,12 +174,13 @@ char *(strchr)(const char *s, int c)
|
||||
*/
|
||||
char *(strrchr)(const char *s, int c)
|
||||
{
|
||||
const char *p = s + strlen(s);
|
||||
do {
|
||||
if (*p == (char)c)
|
||||
return (char *)p;
|
||||
} while (--p >= s);
|
||||
return NULL;
|
||||
const char *p = s + strlen(s);
|
||||
|
||||
for (; *p != (char)c; --p)
|
||||
if (p == s)
|
||||
return NULL;
|
||||
|
||||
return (char *)p;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||