Browse Source

TT#111150 don't pass null pointers to memchr or memcpy

If the length of the string is zero, the pointer to the buffer may be
null. ASAN flags these as invalid/undefined, so don't do that.

Change-Id: Ic55498465c53a78e1bd44c42d1a60f9bd3336473
mr8.5.11
Richard Fuchs 5 years ago
parent
commit
3775e08bea
1 changed files with 4 additions and 1 deletions
  1. +4
    -1
      lib/str.h

+ 4
- 1
lib/str.h View File

@ -155,6 +155,8 @@ INLINE int str_shift_cmp(str *s, const char *t) {
return 0;
}
INLINE char *str_chr(const str *s, int c) {
if (!s->len)
return NULL;
return memchr(s->s, c, s->len);
}
INLINE char *str_chr_str(str *out, const str *s, int c) {
@ -269,7 +271,8 @@ INLINE str *str_dup(const str *s) {
str *r;
r = str_alloc(s->len);
r->len = s->len;
memcpy(r->s, s->s, s->len);
if (s->len)
memcpy(r->s, s->s, s->len);
r->s[s->len] = '\0';
return r;
}


Loading…
Cancel
Save