CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

uC restarts after run strcpy().

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ricardom



Joined: 04 Nov 2016
Posts: 1

View user's profile Send private message

uC restarts after run strcpy().
PostPosted: Fri Nov 04, 2016 1:00 pm     Reply with quote

I'm working on a command line interpreter on a dsPIC30F4011. I want to get the args from a string that i get from the UART port. The problem: I can get my tokens without any problem, but when i try to copy them to **argv the uC restarts. Am I doing something wrong?.

Btw this function is just a test, right now i'm not intrested on free the memory after using the pointers, i just want to copy tok to a space in argv.

Code:
void parser_argv(char* inputStr)
{    
   char  **argv = malloc(8*sizeof(char*));
     char *auxStr = malloc(BUFFER_SIZE * sizeof(char*));
     unsigned int argc = 0;

     strcpy(auxStr,inputStr);
   char *tok = strtok (auxStr,delimiters);

   if(tok != NULL){
      fprintf(PC_UART,"First Val %s\n",tok);
      while(tok !=NULL){
         tok = strtok (NULL, delimiters);
         strcpy(argv[argc],tok);
         fprintf(PC_UART,"token %s %s\n",argv[argc],tok);
         argc++;
      }
   }
}


Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 04, 2016 5:12 pm     Reply with quote

See this thread at the end:
http://www.ccsinfo.com/forum/viewtopic.php?t=54023
ie., dsPIC stack size.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Sat Nov 05, 2016 2:25 am     Reply with quote

and (of course), has the input string got a null terminator?.
Unless it has strcpy will walk through the memory.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group