Wireshark-dev: Re: [Wireshark-dev] Build failure today
From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Fri, 20 Apr 2018 11:41:05 -0700
On Apr 20, 2018, at 10:57 AM, Martin Mathieson via Wireshark-dev <wireshark-dev@xxxxxxxxxxxxx> wrote:

> I'm getting the error below:
> 
> Looking at the first one, my compiler doesn't seem to realise that compute_offset()  will throw an exception rather than return a number without setting *offset_ptr

That's because it *won't* throw an exception.  It'll return either "no error" or an exception for its caller to deal with.

What the compiler you're using doesn't realize is that nobody who calls compute_offset(), or calls something that calls compute_offset(), or {...(transitive closure of calls) compute_offset()} uses *offset_ptr if the return value is non-zero.  Not all compilers' data flow analysis appears to handle that.

> But when I look at e.g. BoundsError (which may be returned without setting *offset_ptr), it is #defined as 1 in epan/exceptions.h
> 
> Surely the returns in compute_offset() should be THROW() calls instead?

No, because the routines's purpose is to check and, if the offset doesn't exist, return an exception to its caller.  Its caller might throw it or just pass it to its caller.  Some caller up the call chain, such as tvb_bytes_exist(), might just want to return a "these bytes are/aren't available in the captured data" indication rather than throwing an exception.

Dario Lombardo should have fixed that in 1a9f3b8f6d65b50c0eaa78bde29ca50708900178.