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. Clever code [modified]

Clever code [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
htmlcomquestion
18 Posts 12 Posters 115 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.
  • S Steve Hansen

    Well it's checking for 2 line returns so the first thing that comes to mind is SMTP or HTTP :P Last 2 lines are just plain stupid.

    M Offline
    M Offline
    MidwestLimey
    wrote on last edited by
    #7

    First thing that came to my mind too .. though only a 1k limit, bit of a kicker with a long POST request.


    I'm largely language agnostic


    After a while they all bug me :doh:


    1 Reply Last reply
    0
    • D Dario Solera

      I'm trying to figure out how an old C application work.

      i = 0;
      while(i <= 1024) {
      if(RxData[i] == 13 && RxData[i+1] == 10 && RxData[i+2] == 13 && RxData[i+3] == 10)
      break;
      i++;
      }
      PosBD = i;
      i = PosBD;

      EDIT: PosBD and i are declared as int. Although the while body might be quite clever because it's fast (who's brave enough to understand where the code is used?), I really don't get the 2 final lines... :-D -- modified at 13:25 Tuesday 31st July, 2007

      If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #8

      PosBD = i; /* set initial value to value of i */ i = PosBD; /* just too be sure! */ I'd be suspicious that 'PosBD' doesn't hold the value of 1024 too well. But without seeing it's type, that's pure speculation. :0

      Chris Meech I am Canadian. [heard in a local bar]

      1 Reply Last reply
      0
      • D Dario Solera

        I'm trying to figure out how an old C application work.

        i = 0;
        while(i <= 1024) {
        if(RxData[i] == 13 && RxData[i+1] == 10 && RxData[i+2] == 13 && RxData[i+3] == 10)
        break;
        i++;
        }
        PosBD = i;
        i = PosBD;

        EDIT: PosBD and i are declared as int. Although the while body might be quite clever because it's fast (who's brave enough to understand where the code is used?), I really don't get the 2 final lines... :-D -- modified at 13:25 Tuesday 31st July, 2007

        If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

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

        Weeeell.. of course these two lines are to avoid that i has a different reference from PosBD because you forgot to say that the type of i and PosBD is not int. the type of them is SuperInt which is a numeric Reference Type and for some reason we will possibly never understand it's very important that a) a number must be stored as reference in this case b) any changes will be made to i must be done to PosBD as well. just in case that 0 won't be 0 anymore someday..

        1 Reply Last reply
        0
        • D Dario Solera

          I'm trying to figure out how an old C application work.

          i = 0;
          while(i <= 1024) {
          if(RxData[i] == 13 && RxData[i+1] == 10 && RxData[i+2] == 13 && RxData[i+3] == 10)
          break;
          i++;
          }
          PosBD = i;
          i = PosBD;

          EDIT: PosBD and i are declared as int. Although the while body might be quite clever because it's fast (who's brave enough to understand where the code is used?), I really don't get the 2 final lines... :-D -- modified at 13:25 Tuesday 31st July, 2007

          If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

          P Offline
          P Offline
          Pualee
          wrote on last edited by
          #10

          PosBD = i; i = PosBD; The side effects of embedded C code are always amazing. Have you checked the types on these guys or revision history? I am willing to bet one is 16 bit in one file and 32 in another. I'd also wager if that is the case, there is an extern declaration somewhere :) It is possible PosBD is overwriting i and the setting i to PosBD fixes it. A later file using the correct size of PosBD will not be affected! A lazy programmer did not check his/her types. =========== Related experience showing why that might* make sense ============ I once worked on a system with lots of arrays which were global and 16 bit or 32 bit depending on the file they were used in. Needless to say lots of stuff got overwritten and until I realized what the problem was (and fixed it), another engineer did the following temporarily and was baffled:

          = temp;
          another file had this from the legacy system(syntax may be a bit off, its been a while) int16 value[]; int16 checks[]; This fixed the problem, but he never knew why(found exact line w/ debugger). In reality, the checks array was overwriting the value array whenever the index was greater than half its size! After I addressed the extern issues and fixed types, other parts of the system randomly started working or breaking (mostly working), depending on how they had been set up. By the end of the project, I was thanked for fixing things not in the spec... even though I had never touched them :) The client was satisfied. -- modified at 13:07 Tuesday 31st July, 2007

          D 1 Reply Last reply
          0
          • Q QuiJohn

            I also hope that RxData has an array length of (at least) 1028, though somehow I doubt it.


            Faith is a fine invention For gentlemen who see; But microscopes are prudent In an emergency! -Emily Dickinson

            D Offline
            D Offline
            Dario Solera
            wrote on last edited by
            #11

            David Kentley wrote:

            though somehow I doubt it

            :-D

            If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

            1 Reply Last reply
            0
            • P Pualee

              PosBD = i; i = PosBD; The side effects of embedded C code are always amazing. Have you checked the types on these guys or revision history? I am willing to bet one is 16 bit in one file and 32 in another. I'd also wager if that is the case, there is an extern declaration somewhere :) It is possible PosBD is overwriting i and the setting i to PosBD fixes it. A later file using the correct size of PosBD will not be affected! A lazy programmer did not check his/her types. =========== Related experience showing why that might* make sense ============ I once worked on a system with lots of arrays which were global and 16 bit or 32 bit depending on the file they were used in. Needless to say lots of stuff got overwritten and until I realized what the problem was (and fixed it), another engineer did the following temporarily and was baffled:

              = temp;
              another file had this from the legacy system(syntax may be a bit off, its been a while) int16 value[]; int16 checks[]; This fixed the problem, but he never knew why(found exact line w/ debugger). In reality, the checks array was overwriting the value array whenever the index was greater than half its size! After I addressed the extern issues and fixed types, other parts of the system randomly started working or breaking (mostly working), depending on how they had been set up. By the end of the project, I was thanked for fixing things not in the spec... even though I had never touched them :) The client was satisfied. -- modified at 13:07 Tuesday 31st July, 2007

              D Offline
              D Offline
              Dario Solera
              wrote on last edited by
              #12

              Pualee wrote:

              The side effects of embedded C code are always amazing.

              How true. :suss:

              Pualee wrote:

              I am willing to bet one is 16 bit in one file and 32 in another.

              Nope, both 32 bit, in the same file. :)

              If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

              P 1 Reply Last reply
              0
              • S Steve Hansen

                Well it's checking for 2 line returns so the first thing that comes to mind is SMTP or HTTP :P Last 2 lines are just plain stupid.

                D Offline
                D Offline
                Dario Solera
                wrote on last edited by
                #13

                Steve Hansen wrote:

                HTTP

                Bingo!

                If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

                1 Reply Last reply
                0
                • R Rage

                  Must be software for aircraft controlling systems. I heard that they always make things redundant, just in case...

                  Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                  D Offline
                  D Offline
                  Dario Solera
                  wrote on last edited by
                  #14

                  Rage wrote:

                  Must be software for aircraft controlling systems.

                  Luckily, it's not that important. :~

                  If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

                  1 Reply Last reply
                  0
                  • D Dario Solera

                    Pualee wrote:

                    The side effects of embedded C code are always amazing.

                    How true. :suss:

                    Pualee wrote:

                    I am willing to bet one is 16 bit in one file and 32 in another.

                    Nope, both 32 bit, in the same file. :)

                    If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

                    P Offline
                    P Offline
                    Pualee
                    wrote on last edited by
                    #15

                    I modified that post, check other files, is either variable externally declared with different types in other files? Well... gave it my best effort :) I guess my constant edits make it hard to understand my post, but its such an odd issue to explain, but when experienced, you'll never forget it X|

                    1 Reply Last reply
                    0
                    • D Dario Solera

                      I'm trying to figure out how an old C application work.

                      i = 0;
                      while(i <= 1024) {
                      if(RxData[i] == 13 && RxData[i+1] == 10 && RxData[i+2] == 13 && RxData[i+3] == 10)
                      break;
                      i++;
                      }
                      PosBD = i;
                      i = PosBD;

                      EDIT: PosBD and i are declared as int. Although the while body might be quite clever because it's fast (who's brave enough to understand where the code is used?), I really don't get the 2 final lines... :-D -- modified at 13:25 Tuesday 31st July, 2007

                      If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

                      S Offline
                      S Offline
                      sngbrdb
                      wrote on last edited by
                      #16

                      Agree with others, without knowing the types and context of this code, it's hard to say. Seems senseless at first, but in C that's a dangerous assumption. : p No other assembly programmers out there? The first thing I thought was the second assignment set the zero flag : ) I'm inclined to think it's just a bit of bad coding... the giveaway is the fact that if there are no instances of 13-10-13-10 in the 1024 bytes the app will overflow on the 1021st iteration (unless the array allocated 1027 bytes, which would just be sloppy and still make me think it's crap code). I did think briefly about pointers, and pointers to pointers, but even that doesn't fit (no *s or &s). It's just bad code, anyway you look at it. What does PosBD stand for? Position of... Bad Data? BartDude? Maybe that would give some clue of what he was trying to do.

                      S 1 Reply Last reply
                      0
                      • R Rage

                        Must be software for aircraft controlling systems. I heard that they always make things redundant, just in case...

                        Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                        S Offline
                        S Offline
                        StevenWalsh
                        wrote on last edited by
                        #17

                        5.... because thats halarious

                        1 Reply Last reply
                        0
                        • S sngbrdb

                          Agree with others, without knowing the types and context of this code, it's hard to say. Seems senseless at first, but in C that's a dangerous assumption. : p No other assembly programmers out there? The first thing I thought was the second assignment set the zero flag : ) I'm inclined to think it's just a bit of bad coding... the giveaway is the fact that if there are no instances of 13-10-13-10 in the 1024 bytes the app will overflow on the 1021st iteration (unless the array allocated 1027 bytes, which would just be sloppy and still make me think it's crap code). I did think briefly about pointers, and pointers to pointers, but even that doesn't fit (no *s or &s). It's just bad code, anyway you look at it. What does PosBD stand for? Position of... Bad Data? BartDude? Maybe that would give some clue of what he was trying to do.

                          S Offline
                          S Offline
                          StevenWalsh
                          wrote on last edited by
                          #18

                          i was thinking POS stands for Point of Sale... in which case the code came from an inexperienced beginner programmer from India.... in which case its bad code. (please don't misunderstand me... i'm not saying that all programmers from india are bad programmers, i'm just saying the underpaid ones are ;) )

                          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