ROBOTC.net forums
http://www.robotc.net/forums/

RobotC 3.51 Bug #2 - Brick crashing
http://www.robotc.net/forums/viewtopic.php?f=63&t=4921
Page 1 of 1

Author:  nateww [ Sat Sep 29, 2012 1:08 pm ]
Post subject:  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);
}

Author:  MHTS [ Sat Sep 29, 2012 2:16 pm ]
Post subject:  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);
}

Author:  nateww [ Sat Sep 29, 2012 9:42 pm ]
Post subject:  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

Author:  MHTS [ Sun Sep 30, 2012 1:10 am ]
Post subject:  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.

Author:  Dick Swan [ Tue Oct 02, 2012 12:12 am ]
Post subject:  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.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/