clang's -fcatch-undefined-behavior and detect_C89_integers() in H5detect.c:1285

Hi all,

I have been experimenting with clang's -fcatch-undefined-behavior, which does like its name implies. For details:

<http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html>

This has detected a bug in detect_C89_integers() at H5detect.c line 1285:

DETECT_I(short, SHORT, d_g[nd_g]); nd_g++;

The DETECT_I macro is difficult to decipher, but I'm pretty sure it's doing a left shift that's too big. Shifting a uint16_t by 16 or more bits is undefined.

Could someone familiar with this code investigate?

It's especially annoying because this code seems to run at build time, causing build failure:

<http://cdash.hdfgroup.uiuc.edu/viewBuildError.php?buildid=5482>

Which is much more annoying than just a failing unit test or two.

Cheers,

···

--
____________________________________________________________
Sean McBride, B. Eng sean@rogue-research.com
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada

Sean,

Thank you for reporting! I created a ticket in our issues database (HDFFV-8147). We will try to take a look before our next release, but cannot promise.

If someone on FORUM will have time to investigate and have any questions, we will be more than happy to assist (and to accept a patch :slight_smile:

Thank you!

Elena

···

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Sep 7, 2012, at 3:32 PM, Sean McBride wrote:

Hi all,

I have been experimenting with clang's -fcatch-undefined-behavior, which does like its name implies. For details:

<http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html>

This has detected a bug in detect_C89_integers() at H5detect.c line 1285:

DETECT_I(short, SHORT, d_g[nd_g]); nd_g++;

The DETECT_I macro is difficult to decipher, but I'm pretty sure it's doing a left shift that's too big. Shifting a uint16_t by 16 or more bits is undefined.

Could someone familiar with this code investigate?

It's especially annoying because this code seems to run at build time, causing build failure:

<http://cdash.hdfgroup.uiuc.edu/viewBuildError.php?buildid=5482>

Which is much more annoying than just a failing unit test or two.

Cheers,

--
____________________________________________________________
Sean McBride, B. Eng sean@rogue-research.com
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org