Github user jpeach commented on the pull request: https://github.com/apache/trafficserver/pull/542#issuecomment-203489537 ``ptrdiff_t`` is the right type for pointer arithmetic. That said, I don't really understand the problem here. If ``field`` is not in the ``MIMEFieldBlockImpl`` you are scanning, then the pointer arithmetic is not valid in the first place. For the pointer arithmetic to overflow 32bits, the distance between the pointers would need to be ``2^32 * sizeof(MIMEFieldBlockImpl)``, which seems unlikely. A potential real problem here could be the compiler assuming that the comparison can't happen, since pointer arithmetic across different objects is not standards compliant, see [here](https://lwn.net/Articles/278137/). To address this, I'd add ``MIMEFieldBlockImpl::contains(MIMEField*)``, ```C int mime_hdr_field_slotnum(MIMEHdrImpl *mh, MIMEField *field) { int slots_so_far; MIMEFieldBlockImpl *fblock; slots_so_far = 0; for (fblock = &(mh->m_first_fblock); fblock != NULL; fblock = fblock->m_next) { if (block->contains(field)) { MIMEField *first = &(fblock->m_field_slots[0]); ptrdiff_t block_slot = field - first; // in units of MIMEField return (slots_so_far + block_slot); } slots_so_far += MIME_FIELD_BLOCK_SLOTS; } return -1; } ``` Can you think of a way to write tests for this?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---