BUG: incorrect buffer alignment in pj_pool_create_on_buf()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello developers,

This code sequence in pj_pool_create_on_buf() was discussed on stackoverflow.com[1]:

    /* Check and align buffer */
    align_diff = (pj_size_t)buf;
    if (align_diff & (PJ_POOL_ALIGNMENT-1)) {
	align_diff &= (PJ_POOL_ALIGNMENT-1);
	buf = (void*) (((char*)buf) + align_diff);
	size -= align_diff;
    }

The problem is that it does not round up to the next alignment boundary properly. (align_diff is the distance from the lower alignment boundary, not the distance to the upper alignment boundary.) I suggest the following correction:

    /* Check and align buffer */
    align_diff = (pj_size_t)buf;
    if (align_diff & (PJ_POOL_ALIGNMENT-1)) {
	align_diff &= (PJ_POOL_ALIGNMENT-1);
	align_diff = PJ_POOL_ALIGNMENT - align_diff;
	buf = (void*) (((char*)buf) + align_diff);
	size -= align_diff;
    }

(or something equivalent).

[1] https://stackoverflow.com/questions/59969404/check-and-align-buffer

Regards,
Ian Abbott

--
-=( Ian Abbott <abbotti@xxxxxxxxx> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:    )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-

_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org



[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux