Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Bug of the day

Bug of the day

Scheduled Pinned Locked Moved The Weird and The Wonderful
help
37 Posts 23 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Delphi4ever

    if(SomeThing == SomeOtherThing); { DoSomeThing; } This one has been sitting in the codebase for a couple of years... :(( At least it did SomeThing...

    Richard DeemingR Offline
    Richard DeemingR Offline
    Richard Deeming
    wrote on last edited by
    #2

    Which language? The C# compiler will give you a warning for that: "Possible mistaken empty statement".


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

    B 1 Reply Last reply
    0
    • Richard DeemingR Richard Deeming

      Which language? The C# compiler will give you a warning for that: "Possible mistaken empty statement".


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #3

      Even C back in the old days gave you a warning for that.

      K 1 Reply Last reply
      0
      • D Delphi4ever

        if(SomeThing == SomeOtherThing); { DoSomeThing; } This one has been sitting in the codebase for a couple of years... :(( At least it did SomeThing...

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #4

        Does that even compile? /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        T 1 Reply Last reply
        0
        • D Delphi4ever

          if(SomeThing == SomeOtherThing); { DoSomeThing; } This one has been sitting in the codebase for a couple of years... :(( At least it did SomeThing...

          A Offline
          A Offline
          anton_l
          wrote on last edited by
          #5

          It seems that problem is in semicolon after "if" statement. DoSomeThing will be fired any time the code executes.

          K 1 Reply Last reply
          0
          • D Delphi4ever

            if(SomeThing == SomeOtherThing); { DoSomeThing; } This one has been sitting in the codebase for a couple of years... :(( At least it did SomeThing...

            Y Offline
            Y Offline
            YvesDaoust
            wrote on last edited by
            #6

            This is one of the dangers of C syntax (and friends). That's the price you pay for willing conciseness. Block-only statements like VB's

            If Condition Then
            Statement
            End If

            or Modula's

            IF Condition THEN
            Statement
            END

            are safer.

            G 1 Reply Last reply
            0
            • D Delphi4ever

              if(SomeThing == SomeOtherThing); { DoSomeThing; } This one has been sitting in the codebase for a couple of years... :(( At least it did SomeThing...

              B Offline
              B Offline
              Bernhard Hiller
              wrote on last edited by
              #7

              Oh no, you misunderstood the guy who wrote that piece of code. Never did he intend that DoSomeThing() is executed only when some codition is true. He just wanted to make his colleagues (who'll have to maintain his buggy code after he quit his job) believe so.

              1 Reply Last reply
              0
              • D Delphi4ever

                if(SomeThing == SomeOtherThing); { DoSomeThing; } This one has been sitting in the codebase for a couple of years... :(( At least it did SomeThing...

                R Offline
                R Offline
                R Erasmus
                wrote on last edited by
                #8

                Seems like a new style of comment... if you're compiler doesn't support any comments. ;P

                "Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>

                1 Reply Last reply
                0
                • B BobJanova

                  Even C back in the old days gave you a warning for that.

                  K Offline
                  K Offline
                  Klaus Werner Konrad
                  wrote on last edited by
                  #9

                  Wich compiler ?

                  while (*dest++ = *source++);

                  is completely correct, isn't it ?

                  B L 2 Replies Last reply
                  0
                  • K Klaus Werner Konrad

                    Wich compiler ?

                    while (*dest++ = *source++);

                    is completely correct, isn't it ?

                    B Offline
                    B Offline
                    BobJanova
                    wrote on last edited by
                    #10

                    It's a warning, not an error, for that reason. This was back when I used Zortech's ANSI C compiler.

                    1 Reply Last reply
                    0
                    • Y YvesDaoust

                      This is one of the dangers of C syntax (and friends). That's the price you pay for willing conciseness. Block-only statements like VB's

                      If Condition Then
                      Statement
                      End If

                      or Modula's

                      IF Condition THEN
                      Statement
                      END

                      are safer.

                      G Offline
                      G Offline
                      Gary Wheeler
                      wrote on last edited by
                      #11

                      Or Pascal:

                      if condition then
                      begin
                      DoStuff();
                      end
                      else
                      begin
                      DoOtherStuff();
                      end;

                      Sort an 'are you sure?' prompt for every single conditional. :rolleyes:

                      Software Zen: delete this;

                      B 1 Reply Last reply
                      0
                      • G Gary Wheeler

                        Or Pascal:

                        if condition then
                        begin
                        DoStuff();
                        end
                        else
                        begin
                        DoOtherStuff();
                        end;

                        Sort an 'are you sure?' prompt for every single conditional. :rolleyes:

                        Software Zen: delete this;

                        B Offline
                        B Offline
                        BobJanova
                        wrote on last edited by
                        #12

                        Can't you do if condition then one-statement else other-statement though if you don't need a block?

                        G 1 Reply Last reply
                        0
                        • B BobJanova

                          Can't you do if condition then one-statement else other-statement though if you don't need a block?

                          G Offline
                          G Offline
                          Gary Wheeler
                          wrote on last edited by
                          #13

                          Yes, but I've always hated doing those, unless you write it on a single line:

                          if condition then DoSomething() else DoOtherThing();

                          That's the only way in my mind to avoid stupid mistakes like this:

                          if condition then
                          DoThing1();
                          DoThing2();
                          DoThing3();
                          MainStuff();

                          DoThing2() and DoThing3() look like they're part of the if, but they're not. I do the same thing in C-style languages. If an if-statement occupies more than one line, it gets braced.

                          Software Zen: delete this;

                          B L S 3 Replies Last reply
                          0
                          • D Delphi4ever

                            if(SomeThing == SomeOtherThing); { DoSomeThing; } This one has been sitting in the codebase for a couple of years... :(( At least it did SomeThing...

                            F Offline
                            F Offline
                            Fabio Franco
                            wrote on last edited by
                            #14

                            I had to read it three times before spotting the problem. Go bugged by the fact that DoSomeThing didn't have parenthesis.

                            To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                            G 1 Reply Last reply
                            0
                            • G Gary Wheeler

                              Yes, but I've always hated doing those, unless you write it on a single line:

                              if condition then DoSomething() else DoOtherThing();

                              That's the only way in my mind to avoid stupid mistakes like this:

                              if condition then
                              DoThing1();
                              DoThing2();
                              DoThing3();
                              MainStuff();

                              DoThing2() and DoThing3() look like they're part of the if, but they're not. I do the same thing in C-style languages. If an if-statement occupies more than one line, it gets braced.

                              Software Zen: delete this;

                              B Offline
                              B Offline
                              BobJanova
                              wrote on last edited by
                              #15

                              I agree and would always put that on a single line.

                              1 Reply Last reply
                              0
                              • F Fabio Franco

                                I had to read it three times before spotting the problem. Go bugged by the fact that DoSomeThing didn't have parenthesis.

                                To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                G Offline
                                G Offline
                                gervacleto
                                wrote on last edited by
                                #16

                                Me too. I didn't see the semicolon until I review it two or three times. So maybe it is not a trap but a genuine bug. Some times you check your code 10 times and do not see this kind of bugs. :-\

                                You may forget having good days, just because you are remembering the past or thinking too much about the future. Live now and enjoy the moment!!

                                F 1 Reply Last reply
                                0
                                • G gervacleto

                                  Me too. I didn't see the semicolon until I review it two or three times. So maybe it is not a trap but a genuine bug. Some times you check your code 10 times and do not see this kind of bugs. :-\

                                  You may forget having good days, just because you are remembering the past or thinking too much about the future. Live now and enjoy the moment!!

                                  F Offline
                                  F Offline
                                  Fabio Franco
                                  wrote on last edited by
                                  #17

                                  Tell me about it. I'm specially vulnerable to problems that are right in front of my face. I do this too often: :doh: Maybe it's my short span of attention.

                                  To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                  G 1 Reply Last reply
                                  0
                                  • F Fabio Franco

                                    Tell me about it. I'm specially vulnerable to problems that are right in front of my face. I do this too often: :doh: Maybe it's my short span of attention.

                                    To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                    G Offline
                                    G Offline
                                    gervacleto
                                    wrote on last edited by
                                    #18

                                    This errors can be present in C like language. The last only in C# This one is usual (very)

                                    if(Something)
                                    One();
                                    two();
                                    ...

                                    Of course only One() is inside the if(), but it seems that the other two instructions are inside also. I did fall in this bug many times until I decided to enclose into curly braces any if() or loop with one or more instructions. It could increase the number of lines, but, for sure, decrease the bugs. Other one:

                                    bool MyBoolValue = true;

                                    if(MyBoolValue = false){
                                    ... SomeStuff ...
                                    }

                                    Maybe the compiler throws a warning, but this statement is valid. Surely is not what you want to do because you have omitted one equal sign:

                                    if(MyBoolValue == false)...

                                    I have no solution to this one, but to check again :sigh: Of course the comparison is not necessary, because MyBoolValue is true or false per se. ;)

                                    if(MyBoolValue)...

                                    for(int i = 0; i < MyArray.GetUpperBound(0); i++){
                                    SomeStuff....
                                    }

                                    You must remember that GetUpperBound(0) does not start in '0' but in '1', because is the number of elements not the dimensions of the array so it must be:

                                    for(int i = 0; i <= MyArray.GetUpperBound(0); i++)

                                    I will try to remember more "Mistakes" that are common for me, but for sure here are more qualified people to show you many more.

                                    You may forget having good days, just because you are remembering the past or thinking too much about the future. Live now and enjoy the moment!!

                                    P F 2 Replies Last reply
                                    0
                                    • G gervacleto

                                      This errors can be present in C like language. The last only in C# This one is usual (very)

                                      if(Something)
                                      One();
                                      two();
                                      ...

                                      Of course only One() is inside the if(), but it seems that the other two instructions are inside also. I did fall in this bug many times until I decided to enclose into curly braces any if() or loop with one or more instructions. It could increase the number of lines, but, for sure, decrease the bugs. Other one:

                                      bool MyBoolValue = true;

                                      if(MyBoolValue = false){
                                      ... SomeStuff ...
                                      }

                                      Maybe the compiler throws a warning, but this statement is valid. Surely is not what you want to do because you have omitted one equal sign:

                                      if(MyBoolValue == false)...

                                      I have no solution to this one, but to check again :sigh: Of course the comparison is not necessary, because MyBoolValue is true or false per se. ;)

                                      if(MyBoolValue)...

                                      for(int i = 0; i < MyArray.GetUpperBound(0); i++){
                                      SomeStuff....
                                      }

                                      You must remember that GetUpperBound(0) does not start in '0' but in '1', because is the number of elements not the dimensions of the array so it must be:

                                      for(int i = 0; i <= MyArray.GetUpperBound(0); i++)

                                      I will try to remember more "Mistakes" that are common for me, but for sure here are more qualified people to show you many more.

                                      You may forget having good days, just because you are remembering the past or thinking too much about the future. Live now and enjoy the moment!!

                                      P Offline
                                      P Offline
                                      Pablo Aliskevicius
                                      wrote on last edited by
                                      #19

                                      I usually prefer:

                                      if (42 == ComputeSomeThing(x)) {
                                      //...
                                      }

                                      This one avoids the = against == pit. Another thing I do: my IDE is configured to show operators (like '(){};,+-=...') in color, so they are a bit harder to miss (like the original example). There are two other tools that can help with this: compiler warnings, and static code analysis. JM2B,

                                      Pablo. "Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).

                                      S 1 Reply Last reply
                                      0
                                      • G gervacleto

                                        This errors can be present in C like language. The last only in C# This one is usual (very)

                                        if(Something)
                                        One();
                                        two();
                                        ...

                                        Of course only One() is inside the if(), but it seems that the other two instructions are inside also. I did fall in this bug many times until I decided to enclose into curly braces any if() or loop with one or more instructions. It could increase the number of lines, but, for sure, decrease the bugs. Other one:

                                        bool MyBoolValue = true;

                                        if(MyBoolValue = false){
                                        ... SomeStuff ...
                                        }

                                        Maybe the compiler throws a warning, but this statement is valid. Surely is not what you want to do because you have omitted one equal sign:

                                        if(MyBoolValue == false)...

                                        I have no solution to this one, but to check again :sigh: Of course the comparison is not necessary, because MyBoolValue is true or false per se. ;)

                                        if(MyBoolValue)...

                                        for(int i = 0; i < MyArray.GetUpperBound(0); i++){
                                        SomeStuff....
                                        }

                                        You must remember that GetUpperBound(0) does not start in '0' but in '1', because is the number of elements not the dimensions of the array so it must be:

                                        for(int i = 0; i <= MyArray.GetUpperBound(0); i++)

                                        I will try to remember more "Mistakes" that are common for me, but for sure here are more qualified people to show you many more.

                                        You may forget having good days, just because you are remembering the past or thinking too much about the future. Live now and enjoy the moment!!

                                        F Offline
                                        F Offline
                                        Fabio Franco
                                        wrote on last edited by
                                        #20

                                        gervacleto wrote:

                                        if(Something) One(); two(); ...

                                        This can also happen in C#, but auto indent of Visual Studio makes you less likely to fall in this trap.

                                        gervacleto wrote:

                                        if(MyBoolValue = false){

                                        This happened to me several times and the warning saved. I always pay attention to warnings.

                                        gervacleto wrote:

                                        if(MyBoolValue)

                                        I do not consider this a bug, it is actualy a coding style. I do it myself.

                                        gervacleto wrote:

                                        for(int i = 0; i <= MyArray.GetUpperBound(0); i++)

                                        Never used this construct, so I wouldn't know. But will keep my mind to it in case I run into this. Thanks!

                                        To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                        1 Reply Last reply
                                        0
                                        • G Gary Wheeler

                                          Yes, but I've always hated doing those, unless you write it on a single line:

                                          if condition then DoSomething() else DoOtherThing();

                                          That's the only way in my mind to avoid stupid mistakes like this:

                                          if condition then
                                          DoThing1();
                                          DoThing2();
                                          DoThing3();
                                          MainStuff();

                                          DoThing2() and DoThing3() look like they're part of the if, but they're not. I do the same thing in C-style languages. If an if-statement occupies more than one line, it gets braced.

                                          Software Zen: delete this;

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #21

                                          Quote:

                                          If an if-statement occupies more than one line, it gets braced.

                                          Maybe I'm naïve, but I thought everybody did that! :)

                                          G 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups