From: Ian R. <id...@fr...> - 2010-03-04 23:17:28
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 What is the benefit of adding all these NULL pointer assertions? I don't see a big benefit of an assertion failure vs. a segfault. I'm just curious. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkuQP1UACgkQX1gOwKyEAw8CSQCbBAGG+fv6I2nVsEnTPqz7ZCUZ CygAn1UCENMoomI7305dNA8FiiAJLtGj =2Cl+ -----END PGP SIGNATURE----- |
From: Vinson L. <vl...@vm...> - 2010-03-04 23:30:51
|
> -----Original Message----- > From: Ian Romanick [mailto:id...@fr...] > Sent: Thursday, March 04, 2010 3:17 PM > To: mesa3d-dev > Subject: Re: [Mesa3d-dev] Mesa (master): glsl/pp: Add asserts to check for > null pointer deferences. > > > What is the benefit of adding all these NULL pointer assertions? I > don't see a big benefit of an assertion failure vs. a segfault. > > I'm just curious. For static analysis with Coverity Prevent, the added assert will clear a defect report and/or allow it to continue parsing to the next possible defect. |
From: Luca B. <luc...@gm...> - 2010-03-05 00:13:49
|
> For static analysis with Coverity Prevent, the added assert will clear a defect report and/or allow it to continue parsing to the next possible defect. Are these being checked manually and determined to be false positives? If not, then it would be beneficial to not shut up static analysis, since it actually could be a problem. If yes, perhaps it would be useful to have a comment explaining why it is not a false positive, unless the reasoning is often trivial, which means that the static analyzer isn't doing a very good job. Also, is the whole concept of having a static analyzer assume that asserts are true a good idea? Shouldn't it instead specifically attempt to check whether the assertions in the code are always true? (and have some other means to flag false positives, perhaps not involving source modification) Finally, does the checker provide some easy and license-allowed way of making the analysis results public? (e.g. by putting up the same web interface they used for their open source checking demos) BTW, I just looked at one of the assert commits, and found it actually _introduces_ a bug. Look at the assert(attrib_list) added in 706fffbff59be0dc884e1938f1bdf731af1efa3e. This ends up asserting that the attrib_list in glXCreatePixmap is not NULL. But the GLX specification says that it can be NULL, and it will usually be. The memcpy does not crash because when attrib_list is NULL, the length parameter passed to it is 0, as the code before shows. Thus, that commit should be reverted, and replaced with either no change or by surrounding the memcpy with if(attrib_list) or if(i) . Ideally, we could also mark the if, as well as the if(attrib_list) above with unlikely() while we are at it. Are we sure all the other commits like this are correct and actually flag false positives, as opposed to hiding real bugs? |
From: Luca B. <luc...@gm...> - 2010-03-05 00:20:18
|
Just noticed that has already been fixed in 5f40a7aed12500fd6792e2453f495555c3b5c54d with an if(attrib_list). |
From: Vinson L. <vl...@vm...> - 2010-03-05 00:50:12
|
> -----Original Message----- > > BTW, I just looked at one of the assert commits, and found it actually > _introduces_ a bug. > Look at the assert(attrib_list) added in > 706fffbff59be0dc884e1938f1bdf731af1efa3e. > > This ends up asserting that the attrib_list in glXCreatePixmap is not > NULL. > But the GLX specification says that it can be NULL, and it will usually > be. > > The memcpy does not crash because when attrib_list is NULL, the length > parameter passed to it is 0, as the code before shows. > > Thus, that commit should be reverted, and replaced with either no > change or by surrounding the memcpy with if(attrib_list) or if(i) . > Ideally, we could also mark the if, as well as the if(attrib_list) > above with unlikely() while we are at it. > Whether this was a bug or not is subject to interpretation of the C specification. While it doesn't explicitly state so, a reading of the C99 specification sections 7.1.4 (Use of Library functions) and 7.21.1 (String function conventions) suggests that 'memcpy(dst, NULL, 0)' is undefined behavior. <quote> 7.21.1 String function conventions Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4. On such a call, a function that locates a character finds no occurrence, a function that compares two character sequences returns zero, and a function that copies characters copies zero characters. </quote> |
From: Luca B. <luc...@gm...> - 2010-03-05 01:23:13
|
Yes, from the text you quoted it seems it was indeed incorrect. However, it almost surely ran on any common platform, and the added assert introduced a bug because it would trip for valid usage. My point is that the incorrectness of the patch (and the fact that the if above that place checking for the variable being non-null was not removed in that same patch) suggests that whether that variable could actually be null or not was not manually evaluated, which, if actually the case, kind of seems to defeat the purpose of doing static analysis in the first place and seems to be counterproductive by possibly hiding errors from further static analysis. Of course, that is not supposed to detract from the appreciation that such code analysis work deserves. |