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. Clever Code
  4. Bug caused by sloppy programming [modified]

Bug caused by sloppy programming [modified]

Scheduled Pinned Locked Moved Clever Code
helpwindows-admindebugging
7 Posts 4 Posters 16 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.
  • R Offline
    R Offline
    Rama Krishna Vavilala
    wrote on last edited by
    #1

    bool ProcessRegistryValue()
    {
    DWORD dwValue = 0;

    CRegKey key;
    if (key.Open(HKLM, TEXT("Software\\Company\\Product")) == ERROR_SUCCESS)
    {
    if (key.QueryDWORDValue(TEXT("SomeValue"), dwValue) == ERROR_SUCCESS)
    {
    //Use the dwValue

      return true;
    }
    

    }

    return false;
    }

    //From some code
    if (ProcessRegistryValue())
    {
    //Do some cool stuff
    }
    else
    {
    //Highly unexpected that the func will fail
    //Suppress cool stuff and inform the user
    }

    The registry value was written by the installer. The code worked for a few years without any issues and then one day a user got issues. The application was not doing cool stuff which some other users saw. -- modified at 12:05 Wednesday 27th September, 2006


    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

    PJ ArendsP L 2 Replies Last reply
    0
    • R Rama Krishna Vavilala

      bool ProcessRegistryValue()
      {
      DWORD dwValue = 0;

      CRegKey key;
      if (key.Open(HKLM, TEXT("Software\\Company\\Product")) == ERROR_SUCCESS)
      {
      if (key.QueryDWORDValue(TEXT("SomeValue"), dwValue) == ERROR_SUCCESS)
      {
      //Use the dwValue

        return true;
      }
      

      }

      return false;
      }

      //From some code
      if (ProcessRegistryValue())
      {
      //Do some cool stuff
      }
      else
      {
      //Highly unexpected that the func will fail
      //Suppress cool stuff and inform the user
      }

      The registry value was written by the installer. The code worked for a few years without any issues and then one day a user got issues. The application was not doing cool stuff which some other users saw. -- modified at 12:05 Wednesday 27th September, 2006


      Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      Rama Krishna Vavilala wrote:

      if (key.QueryDWORDValue(TEXT("SomeValue"), dwValue))

      QueryDWORDValue() returns ERROR_SUCCESS if it works. ERROR_SUCCESS is zero, so the if() test fails if the call succeeds. Oh sure, modify your post so the bug is not so obvious. Now I have to start all over:doh:

      Last modified: 4mins after originally posted -- Rama's mod made this post obsolete


      You may be right I may be crazy -- Billy Joel -- Within you lies the power for good, use it!!!

      Within you lies the power for good; Use it!

      R 1 Reply Last reply
      0
      • PJ ArendsP PJ Arends

        Rama Krishna Vavilala wrote:

        if (key.QueryDWORDValue(TEXT("SomeValue"), dwValue))

        QueryDWORDValue() returns ERROR_SUCCESS if it works. ERROR_SUCCESS is zero, so the if() test fails if the call succeeds. Oh sure, modify your post so the bug is not so obvious. Now I have to start all over:doh:

        Last modified: 4mins after originally posted -- Rama's mod made this post obsolete


        You may be right I may be crazy -- Billy Joel -- Within you lies the power for good, use it!!!

        R Offline
        R Offline
        Rama Krishna Vavilala
        wrote on last edited by
        #3

        Sorry Nish pointed that out. The QueryDwodValue is not the issue it was a typo.


        Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

        1 Reply Last reply
        0
        • R Rama Krishna Vavilala

          bool ProcessRegistryValue()
          {
          DWORD dwValue = 0;

          CRegKey key;
          if (key.Open(HKLM, TEXT("Software\\Company\\Product")) == ERROR_SUCCESS)
          {
          if (key.QueryDWORDValue(TEXT("SomeValue"), dwValue) == ERROR_SUCCESS)
          {
          //Use the dwValue

            return true;
          }
          

          }

          return false;
          }

          //From some code
          if (ProcessRegistryValue())
          {
          //Do some cool stuff
          }
          else
          {
          //Highly unexpected that the func will fail
          //Suppress cool stuff and inform the user
          }

          The registry value was written by the installer. The code worked for a few years without any issues and then one day a user got issues. The application was not doing cool stuff which some other users saw. -- modified at 12:05 Wednesday 27th September, 2006


          Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

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

          The call to key.Open requests KEY_WRITE access by default, which will fail on some PCs as the user won't necessarily have Administrator rights (not to HKEY_LOCAL_MACHINE anyway!). I have been bitten by this in the past too.


          Kicking squealing Gucci little piggy.

          R 1 Reply Last reply
          0
          • L Lost User

            The call to key.Open requests KEY_WRITE access by default, which will fail on some PCs as the user won't necessarily have Administrator rights (not to HKEY_LOCAL_MACHINE anyway!). I have been bitten by this in the past too.


            Kicking squealing Gucci little piggy.

            R Offline
            R Offline
            Rama Krishna Vavilala
            wrote on last edited by
            #5

            Yes.:) Started happening after users moved to XP. Actually in the original code, HKEY_CLASSES_ROOT was causing the problem. The default security for HKCR in Windows 2000 was more permissive than in XP.


            Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

            M 1 Reply Last reply
            0
            • R Rama Krishna Vavilala

              Yes.:) Started happening after users moved to XP. Actually in the original code, HKEY_CLASSES_ROOT was causing the problem. The default security for HKCR in Windows 2000 was more permissive than in XP.


              Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

              M Offline
              M Offline
              Mike Dimmick
              wrote on last edited by
              #6

              Rama Krishna Vavilala wrote:

              The default security for HKCR in Windows 2000 was more permissive than in XP.

              More likely that the user was a member of the Power Users group. I'm pretty sure that Windows 2000 and XP have the same permissions for Users. HKEY_CLASSES_ROOT, as of Windows 2000, is not really a root key. It's actually a merged view of HKEY_LOCAL_MACHINE\Software\Classes and HKEY_CURRENT_USER\Software\Classes. The data under HKCU does not roam for a roaming profile, it's specific to the machine. HKCU overrides HKLM. Too few programs take advantage of this: Windows Media Player, for example, simply hides the 'File Types' tab if the user isn't an administrator, rather than writing the user's preferences to HKCU\Software\Classes.

              Stability. What an interesting concept. -- Chris Maunder

              R 1 Reply Last reply
              0
              • M Mike Dimmick

                Rama Krishna Vavilala wrote:

                The default security for HKCR in Windows 2000 was more permissive than in XP.

                More likely that the user was a member of the Power Users group. I'm pretty sure that Windows 2000 and XP have the same permissions for Users. HKEY_CLASSES_ROOT, as of Windows 2000, is not really a root key. It's actually a merged view of HKEY_LOCAL_MACHINE\Software\Classes and HKEY_CURRENT_USER\Software\Classes. The data under HKCU does not roam for a roaming profile, it's specific to the machine. HKCU overrides HKLM. Too few programs take advantage of this: Windows Media Player, for example, simply hides the 'File Types' tab if the user isn't an administrator, rather than writing the user's preferences to HKCU\Software\Classes.

                Stability. What an interesting concept. -- Chris Maunder

                R Offline
                R Offline
                Rama Krishna Vavilala
                wrote on last edited by
                #7

                Might have been. It's been a long time since the bug got fixed

                Mike Dimmick wrote:

                Too few programs take advantage of this

                Ahem.. http://www.codeproject.com/w2k/regsvrex.asp[^] :)


                Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

                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