Thread: wild pointers

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    1

    wild pointers

    Hi,
    This is ravi rajeev working with TCS. I have problem with wild pointers. In the following code i am not able to find out the wild pointer .If some one will give me some idea how to find wild pointer and how to eliminate it,i will be greatful to you.

    Following is the part of code (i.e. function) in which there is wild pointer as per my reviewer comments,

    Code:
    static void 
      handleGetLHName(union SIGNAL *sigrec_p)      /* This function is called when CELLO_PIU3_GET_LH_NAME_CFM signal is received */
      {
         union SIGNAL *huntSig_p;
         char         *lnhName_p;
         U8           huntPath_p[100];
         U32 piuId;
         XpResource *xp_p;
      
      ENTER("handleGetLHName");
      
      huntSig_p = alloc(sizeof(OsaXpHuntFanSupervisionServer),
                       OSA_XP_HUNT_FANSUPERVISION_SERVER);
      huntSig_p->OsaXpHuntFanSupervisionServer_r.xpInstanceId = xp_p->xpInstanceId;
      huntSig_p->OsaXpHuntFanSupervisionServer_r.piuId = piuId;
    
      /* Change the state of the fan supervision server. */
      if(xp_p->fanSupervisionServer1.piuId == piuId)
      {
        xp_p->fanSupervisionServer1.state = FAN_SUPERVISION_SERVER_HUNTING;
        TRACE(7, STR("fanSupervisionServer1 state: %d",
                     xp_p->fanSupervisionServer1.state));
      }
      else if(xp_p->fanSupervisionServer2.piuId == piuId)
      {
        xp_p->fanSupervisionServer2.state = FAN_SUPERVISION_SERVER_HUNTING;
        TRACE(7, STR("fanSupervisionServer2 state: %d",
                     xp_p->fanSupervisionServer2.state));
      }
      else
      {
        TRACE_ERROR(STR("\n%s \n%s%d",
                        "Unknown piuId for fan supervision server.",
                        "piuId: ", piuId));
      }
    
      /* Create the hunt path. */
      strcpy(huntPath_p, lnhName_p);
      strcat(huntPath_p, "/");
      strcat(huntPath_p, OSA_FAN_SUPERVISION_PROC_NAME);
    
      hunt(huntPath_p, (OSUSER)0, 0, &huntSig_p);
    
      /* The linkhandler string needs to be deallocated according
         to the User's Guide for PRI. */
        
         FREE_BUF((union SIGNAL **)&lnhName_p); 
         
         RETURN;
      }

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    37
    Hey man,

    The code that you have posted is a part of major code tree, so its difficult to say what exactly it is, just by looking at a small piece of code. The declarations are not std. you would have header files for the abstraction that you are having . I would suggest that you trace the pgm and try to fig. your self.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'll assume that alloc has some way to let you know it failed to allocate memory, like returning NULL. You never bother checking that.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > char *lnhName_p;
    This is where you start

    > strcpy(huntPath_p, lnhName_p);
    This is what you do next.

    Copying an uninitialised pointer - tell me you know that's a "bad thing"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  3. Wild Pointers?!!
    By Nectron in forum C++ Programming
    Replies: 3
    Last Post: 07-07-2003, 03:06 PM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM