Jump to content
Sign in to follow this  
chmotori

Boostc 6.92 For Pic18

Recommended Posts

Hi,

 

I'm compiling a project for PIC18F46K20, the string library function unsigned char strlen(const char *src) returns incorrect string length on some occasions. I tried to investigate to get more hints, but didn't understand how to replicate the bug consistently. It occurs for some strings, while it doesn't for some others. All strings are in ram, pointed by a char *variable. As far as I can see, the value of the pointer is correctly passed to the library function, but after that I lose control of what's happening inside.... Let me know if you want me to post my project (it's a big project, almost 50K).

 

Elpidio Scaroni

Share this post


Link to post
Share on other sites

chmotori,

Hi,

 

I'm compiling a project for PIC18F46K20, the string library function unsigned char strlen(const char *src) returns incorrect string length on some occasions. I tried to investigate to get more hints, but didn't understand how to replicate the bug consistently. It occurs for some strings, while it doesn't for some others. All strings are in ram, pointed by a char *variable. As far as I can see, the value of the pointer is correctly passed to the library function, but after that I lose control of what's happening inside.... Let me know if you want me to post my project (it's a big project, almost 50K).

 

Elpidio Scaroni

This issue has been fixed in BoostC V6.93 RC3.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Thanxs, in the meantime I did some further investigations...

 

here is the disassembly listing of strlen library function:

 

--- E:\Prg\SourceBoost\compiler\picantc\libc\string.c ------------------------------------------

 

3272 6B95 CLRF 0x95, BANKED

3274 5194 MOVF 0x94, W, BANKED

3276 6EEA MOVWF 0xfea, ACCESS

3278 5193 MOVF 0x93, W, BANKED

327A 6EE9 MOVWF 0xfe9, ACCESS

327C 5195 MOVF 0x95, W, BANKED

327E 2B95 INCF 0x95, F, BANKED

3280 26E9 ADDWF 0xfe9, F, ACCESS

3282 50EE MOVF 0xfee, W, ACCESS

3284 6F96 MOVWF 0x96, BANKED

3286 5396 MOVF 0x96, F, BANKED

3288 E1F5 BNZ 0x3274

328A 52EF MOVF 0xfef, F, ACCESS <-- this is where I think the bug is!

328C E1F3 BNZ 0x3274

328E 0795 DECF 0x95, F, BANKED

3290 0012 RETURN 0

 

 

Explanation: at address 328A, reading the memory pointed by INDF0 returns the memory location right after the termination char of the string, since the FSR0H:L has been post-incremented by the instruction at address 3282. if, by chance, the byte after the termination is not null, the loop goes back to the start.

 

Regards, Elpidio

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...