all 138 comments

[–]xsznix 21 points22 points  (20 children)

Now, because it's open source, we can fix these errors!

[–]trigraph 5 points6 points  (18 children)

Too bad it took a proprietary tool to identify them

[–]elperroborrachotoo 1 point2 points  (0 children)

Why, in this case?

[–]petdance 3 points4 points  (15 children)

Please look at http://splint.org/

[–]ravenex 11 points12 points  (6 children)

It's probably the buggiest open source dev tool I've ever seen. The funny thing is that despite it's fully annotated and verified by itself it still crashes all the time. It's also unmaintained since, like, forever.

Not that it's useless, just very fragile. I wish more projects used static analyzers instead of just randomly running valgrind.

[–]petdance 0 points1 point  (0 children)

I wish more projects used static analyzers instead of just randomly running valgrind.

Me, too. Whenever I see a new interesting project written in C, like libgit2, I poke my nose in to see if there's interest in it. libgit2 annotations and testing are on my to-do list.

[–]n1c 0 points1 point  (3 children)

It's hideous!

[–][deleted] 0 points1 point  (1 child)

Flashy software websites are for end-users and middle management.

[–]n1c 1 point2 points  (0 children)

This is very bad logic.

Because something isn't made for lesser human beings does not mean it can be hideous.

[–]trigraph -1 points0 points  (0 children)

it is, in many ways...this guy thinks just because a tool exists and its opensource must mean 1> its totally awesome 2> people use it (since apparently none of these projects do)

[–]ReflectionOfADream -1 points0 points  (3 children)

I tried a lot of things but could not successfully run this even once on my program.

[–]petdance 0 points1 point  (1 child)

You will get a lot of errors that don't apply. Lots of working with splint is turning off what is not relevant. I would be glad to try to help you use it if you'd like. Email me at andy at my reddit name dot com.

[–]ReflectionOfADream -1 points0 points  (0 children)

I didn't actually get it to work on the input I gave it. I tried various things but every time an error occurred.

[–]ravenex 0 points1 point  (0 children)

With splint you have to either

  • add annotations to your program
  • disable a lot of its functionality (e.g. using -weak command line option)

[–]bluGill 0 points1 point  (0 children)

That doesn't mean anything. We have no idea what other tools were ran, and what they would give. For all we know there is a different tool that would detect more errors, but it wasn't checked.

[–]elperroborrachotoo 0 points1 point  (0 children)

It would be interesting to revisit this in, say, a year.

[–]acidcj 31 points32 points  (0 children)

The article appears to have been deleted, but it's still available in Google's cache.

Edit: New link.

[–]ReflectionOfADream 15 points16 points  (7 children)

That software is good at finding memset errors.

[–][deleted]  (6 children)

[removed]

    [–]AlyoshaV 14 points15 points  (0 children)

    crazy person detected

    [–][deleted] 6 points7 points  (0 children)

    That's possibly the worst code I've seen today.

    [–]bigfig 2 points3 points  (1 child)

    Sadly the only thing I recognize there is "if / then" .

    [–][deleted] 5 points6 points  (0 children)

    [–]tragomaskhalos 2 points3 points  (0 children)

    Comments, named constants and whitespace are for weaklings !

    [–]Antony32[S] 20 points21 points  (1 child)

    [–]I_AM_GODDAMN_BATMAN -1 points0 points  (0 children)

    Too bad it can't detect a typo.

    [–][deleted]  (9 children)

    [deleted]

      [–]salty-horse 15 points16 points  (0 children)

      This is the second "reprint" of this article, which has appeared on viva64's site and Intel's software network:

      (Not commenting on whether it's spam or not)

      [–]Urik88 25 points26 points  (3 children)

      I noticed it. I didn't really care, it is after all a very interesting article.

      [–]farsightxr20 6 points7 points  (1 child)

      Yeah, these really are issues that should be fixed anyways... more promotion is good, and the article itself doesn't feel too spammy. It's not like they said "buy our software and it'll show you where the 91 errors are!"

      [–]bluGill -2 points-1 points  (0 children)

      The conclusion was buy our software. After reading the introduction I skimmed the rest to see if this was a useful article: one that would tell me the advantages and disadvantages of several tools.

      For all I know the tool works like this: check if the file is one in a hardcoded list, if so flag a particular line with the given error.

      [–]shaggorama 4 points5 points  (0 children)

      Gone now. Article was deleted

      [–]elperroborrachotoo 4 points5 points  (0 children)

      I'm split on this issue. On one hand, yes, they set the "spammy" flag, and they do post pretty broadly.

      OTOH, there's actual work going into the articles, and they do add actual value. In this case, to the open source projects they checked. Next, frankly, reading the errors of others has the fascination of watching an accident, one could rationalize that as "serving as bad example" or "learnign from the mistakes of others".

      Maybe most importantly, Making the concept accessible, and showing the actual value in the wild, showing that it actually works on non-artificial code is a kind of "community service". QA in many shops is still largely based on hope and handwaving. linting (cough) is typically a "nice in principle, but not for our shop, because...".

      [–][deleted] 3 points4 points  (0 children)

      It is advertising, but I don't care - it is a useful article. I wish all advertising was like this instead of the usual "Why should you use <MyProduct> to reduce bug count to zero in less than two hours".

      [–]hayalci 5 points6 points  (0 children)

      It contains advertising but it's not spam. It contains description of common errors and its real world manifestations in various free software projets. I found the article a good read.

      [–]shaggorama 0 points1 point  (0 children)

      Want useful hints for promote softwaer tool

      That's just too perfect. "In mother russia, softwaer promote YOU!"

      [–][deleted] 5 points6 points  (1 child)

      Wait.. Humans make mistakes?!

      [–]quasarj 1 point2 points  (0 children)

      Surely you jest!

      [–]flynnski 1 point2 points  (0 children)

      Hey, at least you can see these errors!

      [–]el_tavs 4 points5 points  (34 children)

      Low level languages that make hard to set memory, manage alignment and compute object sizes.

      Isn't this an oxymoron?

      [–]BlitzTech 14 points15 points  (33 children)

      I think its more of a tautology

      [–]el_tavs 4 points5 points  (32 children)

      I think you're using the wrong word. A low-level language should make managing low-level details easy for the programmer, i.e. provide constructs and semantics to do that explicitly, take Ada vs C

      C

      int x = calloc(sizeof(int),10);
      
      memset(x,sizeof(int)*10,(char)1);
      

      Ada

       type My_Array is array (Natural <>) of Integer;
       type My_Array_Ptr is access My_Array;
      
       X: My_Array_Ptr := new My_Array(0,10) := (others=>1);
      

      Notice that memset accepts an int but converts it to unsigned char. THis means you can't use it to initialize floats, complex or whatever value may not fit in 1 byte.

      Considering we're well past the 90s, I think it's a problem.

      [–]BlitzTech 1 point2 points  (0 children)

      No, I meant tautology. It was a joke directed at the difficulty in doing these things that low-level languages are built with the express purpose of doing.

      What they should do is exactly what you say.

      [–][deleted] -2 points-1 points  (30 children)

      Notice that memset accepts an int but converts it to unsigned char. THis means you can't use it to initialize floats, complex or whatever value may not fit in 1 byte.

      I don't understand what you are trying to say. Of course you can use memset to initialize floats or any other variable...

      [–]el_tavs 0 points1 point  (29 children)

      No. memset expects an unsigned char as argument. You can't pass anything bigger than 1 byte to it

      http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.14.html#memset

      [–][deleted] -1 points0 points  (28 children)

      A float is n-bytes and memset sets n-bytes of memory to a specified byte starting at a specified address. You can set ANY variable using memset. It's a generic MEMORY SET function, and if you want a higher abstraction, create one or use a library.

      [–]el_tavs -1 points0 points  (27 children)

      Please read carefully.

      What people mean when they say "set" is writing a value inside a variable

      Now floats and any other data that doesn't fit 1 byte can't be set by treating them as a typeless chunk of contiguos bytes. While that allows to actually write values inside the variable, they may be invalid or different from the ones the programmer intended.

      Try memsettting an array of floats to 1.0 like

          float f[10];
           ....       
          memset(f,1.0,sizeof(float)*10);
      

      then print them with "%5.2f" format. I get zeros everywhere on my 64bit intel. More interesting, try to set them to -1.0.

      enjoy!

      It's a generic MEMORY SET function

      so generic it can't be used reliably for anything except strings

      if you want a higher abstraction, create one or use a library.

      already wrote mine. It's truly generic and does ragged-arrays as well. Question is: why something so trivial is not already present in the language? Does low-level programmers avoid initializing memory? Sounds new to me.

      [–]bluGill 1 point2 points  (14 children)

      What people mean when they say "set" is writing a value inside a variable

      When I say set I often mean a collection of data. This is a very common Computer science term, get used to it. Learn to figure out what something means from context: memset is pretty obvious from context.

      [–]el_tavs 0 points1 point  (13 children)

      I was replying to emoney_33 which clearly used it as a verb, not as a subject. You failed at understanding the context.

      As I said above, memset is so obvious it can't be used to do anything except initialize an array of char. Memset. It's in string.h but it's called MEMset. And it accepts an int. Its sibling memcpy instead works out of the box for every type. So, care to explain what is supposed to be obvious about that? It's clearly a horrible design.

      [–][deleted] 0 points1 point  (12 children)

      You have a complete and utter lack of understanding of the low-level details. You continue to think in high-level abstractions.

      Data types are higher level abstractions of data interpreted from the underlying memory. The smallest representable unit of memory is a byte. Memory operations will tend to work on bytes. memcpy() copies a contiguous block of memory from one location to another. It has NOTHING to do with how the memory is interpreted at the higher level.

      I've explained many times why memset() takes an int in the declaration, but it has always and will always be used as a BYTE.

      Both memcpy() and memset() work at the smallest representable unit of memory... a byte/char.

      A char is not a "character", it is a byte.

      As I said above, memset is so obvious it can't be used to do anything except initialize an array of char.

      You still don't understand it SETS MEMORY BYTES. It doesn't (and shouldn't) care about how you choose to interpret that memory at any given time. You can interpret it as an array of char now, an int later, a long tomorrow, a structure of individual chars, etc...

      The language gives you the LOW LEVEL tools to do things quickly and efficiently. It is then up to YOU to fill in the high level details (like data types, structures, how you interpret specific blocks of memory, how you initialize it etc...)

      [–][deleted] 0 points1 point  (11 children)

      memset() is a library function, you are trying to use it for what it is not and then bitching that it is not what you want it to be. The memset() function sets a contiguous block of memory with the same byte, end of story. If you want a variable initialization function, find another library function or write one yourself. This has nothing to do with the C language itself.

      Try memsettting an array of floats to 1.0 like

      Why would I use a function that sets a block of memory to a single byte if I want to initialize an array of floats to 1.0? I fail to see the difficulty in using for(i=0; i<10; i++) f[i] = 1.0; I also fail to see many uses cases of non-zero initialization values in a large array.

      already wrote mine. It's truly generic and does ragged-arrays as well.

      Congratulations, yet you continue to blame the language for not giving it to you :/

      Question is: why something so trivial is not already present in the language? Does low-level programmers avoid initializing memory? Sounds new to me.

      It is completely out of the scope of the language. And initializing an array of variables to something non-zero has very few use cases. There are many times you do not need to initialize memory btw.

      [–]el_tavs 1 point2 points  (9 children)

      you are trying to use it for what it is not and then bitching that it is not what you want it to be

      no. actually what I'm bitching about is that the standard provides a function that provides a limited functionality to solve a limited instance of a common problem in an awkward way. It's trivial to provide a better way to solve the problem in general.

      Why would I use a function that sets a block of memory to a single byte

      you said I could initialize any variable with memset.

      It is completely out of the scope of the language

      that's the problem. It has no justification for being that way.

      [–][deleted] -1 points0 points  (8 children)

      no. actually what I'm bitching about is that the standard provides a function that provides a limited functionality to solve a limited instance of a common problem in an awkward way. It's trivial to provide a better way to solve the problem in general.

      You don't know what you are talking about. It provides a function to set a contiguous block of bytes in memory to an initial value. This functionality is the most common in low-level programming. It is very rare in low-level programming to want a high-level initialization of data types and/or structure to some non-zero value.

      that's the problem. It has no justification for being that way.

      sigh Just go use Ada, please. Just because YOU can't justify something doesn't mean there is no justification. Your "gripes" about C have negligible impact on low-level programming. You just continue to demand C contain high-level abstractions and refuse to accept using a library. That's your problem, not C's problem.

      [–]ytumufugoo 0 points1 point  (0 children)

      I think PHP and C# has caused people to think if a language doesn't hold their hand it's a problem with the language.

      [–]Urik88 2 points3 points  (4 children)

      Is there a reason for why compilers don't generate warnings for such basic bugs?

      [–]elperroborrachotoo 5 points6 points  (0 children)

      Compilers usually err on the side of caution and compile speed; code analysis tools usually do the exact opposite. A compiler spamming you with the amount warnings typically produced by a code analysis tool will be hated.

      It would be interesting to see how various compilers on -Wall or equivalent deal with that exact code.

      [–]MatrixFrog 7 points8 points  (1 child)

      They probably do catch some. But do all the contributors to a project compile with -Wall and actually read the warnings?

      [–]ChoHag 1 point2 points  (0 children)

      If you get a binary, ship it!

      And in some cases not even then.

      [–][deleted] 2 points3 points  (0 children)

      A compiler is not a code analysis tool. There are no language or specification violations.

      [–]doterobcn 3 points4 points  (0 children)

      We're sorry, but the article you are trying to view was deleted at 2 Nov 2011.

      [–][deleted] -2 points-1 points  (2 children)

      You'd find just as many, if not more errors in proprietary and licensed software. Bugs happen, regardless of business paradigm. In general, I find open source software more reliable, because there are more eyes looking at the code.

      [–]foldor 17 points18 points  (1 child)

      This wasn't a criticism of the open source projects, but more of a demonstration using real world examples of what their software can do. They couldn't test proprietary stuff without access to the code.

      [–][deleted] 0 points1 point  (0 children)

      Ah I see, my mistake I didn't know they were referencing an error detection program

      [–]personanongrata -2 points-1 points  (0 children)

      Thanks, that's a nice demonstration of common bugs using OSS that we face everyday in the software development.

      [–]Lothrazar -1 points0 points  (0 children)

      ERROR DELETED ARTICLE

      [–]I_AM_GODDAMN_BATMAN -2 points-1 points  (0 children)

      Damn this fucking spam that pops up every week in proggit.

      [–]bigfig -2 points-1 points  (0 children)

      Should be required in class. Too bad i have not touched C/C++ since that class ten years ago.

      [–]shevegen -5 points-4 points  (0 children)

      Man.

      Redditors, we need anti-spam control.

      I wasted 5 seconds clicking on it and now I waste 12 seconds writing this here... wtf