We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I use RealView MDK-ARM 3.15b. When I call tge strstr function to search a substring in a larger string it always return NULL. This is my code
char* ptr; char str1[80] ; char str2[80]; strcpy(str1,"This is a large string"); strcpy(str2,"is"); ptr = strstr(str1,str2);
ptr is NULL.
Any idea ??
Kind regards Luc
Thanks for response!
I did write my own mystrstr() function accepting the same parameters (const char*) and returning same value (char*).
When I call my function mystrstr() it's OK, calling strstr() returns NULL.
Here is my code
char* ptr; char str1[80] ; char str2[80]; strcpy(str1,"This is a large string"); strcpy(str2,"large"); ptr = Mystrstr(str1,str2); printf("\n\r%p",ptr); <== returns the correct pointer ptr = strstr(str1,str2); printf("\n\r%p",ptr); <== returns 0
When I show the disassembly I get following
321: char* ptr; 322: char str1[80] ; 323: char str2[80]; 0x00000B94 2001 MOV R0,#0x01 0x00000B96 4956 LDR R1,[PC,#0x0158] 0x00000B98 7008 STRB R0,[R1,#0x00] 324: strcpy(str1,"This is a large string"); 0x00000B9A A156 ADD R1,PC,#0x0158 0x00000B9C A814 ADD R0,SP,#0x0050 0x00000B9E F006 BL 0x00006ECC - Part #1 0x00000BA0 F995 BL 0x00006ECC - Part #2 325: strcpy(str2,"large"); 326: 0x00000BA2 A15A ADD R1,PC,#0x0168 0x00000BA4 4668 MOV R0,SP 0x00000BA6 F006 BL 0x00006ECC - Part #1 0x00000BA8 F991 BL 0x00006ECC - Part #2 327: ptr = Mystrstr(str1,str2); 0x00000BAA 4669 MOV R1,SP 0x00000BAC A814 ADD R0,SP,#0x0050 0x00000BAE F7FF BL Mystrstr(0x00000AD6) - Part #1 0x00000BB0 FF92 BL Mystrstr(0x00000AD6) - Part #2 0x00000BB2 0004 LSL R4,R0,#0 328: printf("\n\r%p",ptr); 329: 0x00000BB4 0021 LSL R1,R4,#0 0x00000BB6 A057 ADD R0,PC,#0x015C 0x00000BB8 F008 BL 0x00009A3C - Part #1 0x00000BBA FF40 BL 0x00009A3C - Part #2 330: ptr = strstr(str1,str2); 0x00000BBC 46C0 MOV R8,R8 237: { return const_cast<char *>(strstr(const_cast<const char *>(__s1), __s2)); } 0x00000BBE 4669 MOV R1,SP 0x00000BC0 A814 ADD R0,SP,#0x0050 0x00000BC2 F006 BL 0x00006E76 - Part #1 0x00000BC4 F958 BL 0x00006E76 - Part #2 0x00000BC6 0004 LSL R4,R0,#0 331: printf("\n\r%p",ptr); 0x00000BC8 0021 LSL R1,R4,#0 0x00000BCA A052 ADD R0,PC,#0x0148 0x00000BCC F008 BL 0x00009A3C - Part #1 0x00000BCE FF36 BL 0x00009A3C - Part #2
look at the source line numbers 330 -> 237 -> 331 ... Is this normal ?
Nobody ? Maybe some Keil support ?
If you want to get help from Keil support, you'd be advised to go to the support page at:
http://www.keil.com/support/
If it were me, I would want to provide them with as much evidence of the problem as possible and would be very tempted to trace into the strstr function to find out what is really happening.
See that "Support" menu choice at top of the page?
That is the route to Keil support. This forum is not. "Terms of Use" (link you can see at left of this post) contains the following text:
"This forum is not monitored by Keil technical support personnel. Do not expect to receive technical support via this forum."
Thanks for response.
I contacted Keil support, but the support for my product has expired... However I found out that the problem only occur when I use the microlib. Knowing this I googled and did find a patch (RVS31-PA-00002-r3p1-11rel0) that installs a new version of the lib where the problem is solved. Thanks again.