Potential low hanging fruit from PVS-Studio

bearophile bearophileHUGS at lycos.com
Wed Oct 19 15:41:05 PDT 2011


Andrej Mitrovic:

> Perhaps the
> compiler could detect this and emit a warning or stop compilation. To
> work around it, you would have to add a space immediately after the
> equals token if the next token is a minus or plus token. E.g.:
> 
> void main()
> {
>     int x = -1;
> 
>     x =-2;    // ng
>     x =- 2;   // ng
>     x = -2;   // ok
>     x = - 2;  // ok
> 
>     x =+2;    // ng
>     x =+ 2;   // ng
>     x = +2;   // ok
>     x = + 2;  // ok
> }
> 
> Alternatively a simple warning could be emitted.
> 
> However I don't know if this is a common enough bug to worry about, or
> if it could potentially hurt metaprogramming.

It's a cute/scary bug. I think I have never done this bug in recent years, but I'd like to know how much common it is. Google has said it will remove its Google Code Search, so it will get harder to know how often a code pattern is.

---------------------------

"Fragment N3" is caught by the not yet implemented:
http://d.puremagic.com/issues/show_bug.cgi?id=5409

"Fragment N3":


#define SEC_ASN1_CHOICE        0x100000

typedef struct sec_ASN1Template_struct {
  unsigned long kind; 
  ...
} SEC_ASN1Template;

PRBool SEC_ASN1IsTemplateSimple(
  const SEC_ASN1Template *theTemplate)
{
  ...
  if (!theTemplate->kind & SEC_ASN1_CHOICE) {
  ...
}



A related case ("Fragment N4"):


bool GetPlatformFileInfo(...) {
  ...
  info->is_directory =
    file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0;
  ...
}


I have updated the issue 5409 with the Fragment N4. I hope to see eventually see issue 5409 implemented.

Bye,
bearophile


More information about the Digitalmars-d mailing list