Changeset 5468 for pjproject


Ignore:
Timestamp:
Oct 24, 2016 3:22:46 AM (3 years ago)
Author:
nanang
Message:

Misc (re #1945): Avoid calling memchr() or memcpy() with NULL pointer (thanks Kal from the patch).

Location:
pjproject/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/string.h

    r4704 r5468  
    470470PJ_INLINE(char*) pj_strchr( const pj_str_t *str, int chr) 
    471471{ 
     472    if (str->slen == 0) 
     473        return NULL; 
    472474    return (char*) memchr((char*)str->ptr, chr, str->slen); 
    473475} 
  • pjproject/trunk/pjlib/include/pj/string_i.h

    r5229 r5468  
    121121    pj_assert(max >= 0); 
    122122    if (max > src->slen) max = src->slen; 
    123     pj_memcpy(dst->ptr, src->ptr, max); 
     123    if (max > 0) 
     124        pj_memcpy(dst->ptr, src->ptr, max); 
    124125    dst->slen = max; 
    125126    return dst; 
  • pjproject/trunk/pjsip/include/pjsip/print_util.h

    r5237 r5468  
    3030        do { \ 
    3131            if ((str).slen >= (endbuf-buf)) return -1;  \ 
    32             pj_memcpy(buf, (str).ptr, (str).slen); \ 
    33             buf += (str).slen; \ 
     32            if ((str).slen) { \ 
     33                pj_memcpy(buf, (str).ptr, (str).slen); \ 
     34                buf += (str).slen; \ 
     35            } \ 
    3436        } while (0) 
    3537 
  • pjproject/trunk/pjsip/src/pjsip/sip_msg.c

    r5451 r5468  
    20142014 
    20152015    /* Check if host contains IPv6 */ 
    2016     if (pj_memchr(hdr->sent_by.host.ptr, ':', hdr->sent_by.host.slen)) { 
     2016    if (pj_strchr(&hdr->sent_by.host, ':')) { 
    20172017        copy_advance_pair_quote_cond(buf, "", 0, hdr->sent_by.host, '[', ']'); 
    20182018    } else { 
Note: See TracChangeset for help on using the changeset viewer.