diff options
author | Nanang Izzuddin <nanang@teluu.com> | 2016-10-24 03:22:46 +0000 |
---|---|---|
committer | Nanang Izzuddin <nanang@teluu.com> | 2016-10-24 03:22:46 +0000 |
commit | 00aa5887abe1fcef80ed2528aaad9f265c599267 (patch) | |
tree | ae1a92efe11f84ebb8a68cd0cded995c7279880b /pjlib | |
parent | 49d98191016269301f21542cc24ecf9d1a3c38f4 (diff) |
Misc (re #1945): Avoid calling memchr() or memcpy() with NULL pointer (thanks Kal from the patch).
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5468 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r-- | pjlib/include/pj/string.h | 2 | ||||
-rw-r--r-- | pjlib/include/pj/string_i.h | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/pjlib/include/pj/string.h b/pjlib/include/pj/string.h index 57c496f3..cfbdd458 100644 --- a/pjlib/include/pj/string.h +++ b/pjlib/include/pj/string.h @@ -469,6 +469,8 @@ PJ_IDECL(void) pj_strcat2(pj_str_t *dst, const char *src); */ PJ_INLINE(char*) pj_strchr( const pj_str_t *str, int chr) { + if (str->slen == 0) + return NULL; return (char*) memchr((char*)str->ptr, chr, str->slen); } diff --git a/pjlib/include/pj/string_i.h b/pjlib/include/pj/string_i.h index b26d5ead..fd864f3f 100644 --- a/pjlib/include/pj/string_i.h +++ b/pjlib/include/pj/string_i.h @@ -120,7 +120,8 @@ PJ_IDEF(pj_str_t*) pj_strncpy( pj_str_t *dst, const pj_str_t *src, { pj_assert(max >= 0); if (max > src->slen) max = src->slen; - pj_memcpy(dst->ptr, src->ptr, max); + if (max > 0) + pj_memcpy(dst->ptr, src->ptr, max); dst->slen = max; return dst; } |