View unanswered posts | View active topics It is currently Wed Apr 16, 2014 12:03 pm






Reply to topic  [ 5 posts ] 
RobotC 3.51 Bug #2 - Brick crashing 
Author Message
Rookie

Joined: Fri Apr 15, 2011 10:29 am
Posts: 37
Post RobotC 3.51 Bug #2 - Brick crashing
Code:
char *buffer = "abc";

task main()
{
   nxtDisplayString(1, "%c", buffer);
   wait10Msec(500);
}

This should read a single character 'a' and print it out to the screen. However, it crashes my brick.

The following program works fine.
Code:
char *buffer = "abc";

task main()
{
   nxtDisplayString(1, "%c", buffer[0]);
   wait10Msec(500);
}

A more realistic example
Code:
char *buffer = "abc";

task main()
{
   char *bptr = buffer;
   nxtDisplayString(1, "%c", bptr);
   bptr++;
   nxtDisplayString(2, "%c", bptr);
   wait10Msec(500);
}


Sat Sep 29, 2012 1:08 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1342
Post Re: RobotC 3.51 Bug #2 - Brick crashing
nateww wrote:
Code:
char *buffer = "abc";

task main()
{
   nxtDisplayString(1, "%c", buffer);
   wait10Msec(500);
}

This should read a single character 'a' and print it out to the screen. However, it crashes my brick.

buffer is declared as a char pointer and the code above is not really printing the first char on the screen. It should have printed the first byte of the pointer value as a character. So the code is incorrect but Brick should not crash though.
nateww wrote:
A more realistic example
Code:
char *buffer = "abc";

task main()
{
   char *bptr = buffer;
   nxtDisplayString(1, "%c", bptr);
   bptr++;
   nxtDisplayString(2, "%c", bptr);
   wait10Msec(500);
}

If you change your code to the following, it should work.
Code:
char *buffer = "abc";

task main()
{
   char *bptr = buffer;
   nxtDisplayString(1, "%c", *bptr);
   bptr++;
   nxtDisplayString(2, "%c", *bptr);
   wait10Msec(500);
}


Sat Sep 29, 2012 2:16 pm
Profile
Rookie

Joined: Fri Apr 15, 2011 10:29 am
Posts: 37
Post Re: RobotC 3.51 Bug #2 - Brick crashing
MHTS wrote:
If you change your code to the following, it should work.
Code:
char *buffer = "abc";

task main()
{
   char *bptr = buffer;
   nxtDisplayString(1, "%c", *bptr);
   bptr++;
   nxtDisplayString(2, "%c", *bptr);
   wait10Msec(500);
}


*Erk* Boy, is my C rusty. Too many years of Java and other interpreted languages and I lose all my pointer knowledge.

Thanks MHTS!


Nate


Sat Sep 29, 2012 9:42 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1342
Post Re: RobotC 3.51 Bug #2 - Brick crashing
Even the code was wrong, RobotC should not generate code that cause the brick to crash though. I would expect it to display some random value corresponding to the value of the pointer.


Sun Sep 30, 2012 1:10 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post Re: RobotC 3.51 Bug #2 - Brick crashing
MHTS wrote:
Even the code was wrong, RobotC should not generate code that cause the brick to crash though. I would expect it to display some random value corresponding to the value of the pointer.

Yes. Even the wrong code should not crash the brick. I tried to reproduce the crash and couldn't. I suspect this is one that has already been fixed and either has not yet been released or was not released at the time the original bug was reported.

If the problem still persists with the next release, please repost again as I couldn't reproduce the crash using the latest unreleased version of ROBOTC.


Tue Oct 02, 2012 12:12 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.