Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid return point #191

Closed
GoogleCodeExporter opened this issue Sep 19, 2015 · 3 comments
Closed

Invalid return point #191

GoogleCodeExporter opened this issue Sep 19, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
The following is a script that will demonstrate the problem:

//////////////////////////////////////////////
void demo_error()
{
  int value = 5;

  printf("Here's a print statement before quitting.\n");

  if(1) {
    printf("returning; there should be no further output.\n");
    return;
  }

  printf("This statement should not print, and does not.\n");

  switch(value)
  {
    case 5:
      printf("case 5: value = %d\n", value);
      break;
    case 0:
      printf("case 0: value=%d\n", value);
      break;
  }

  printf("This statement also should not and does not print.\n");

  return;
}

demo_error();
//////////////////////////////////////////////


Notice that from this simple script the execution is well defined; there should 
be exactly two printf's called followed by a return from the function.

With that script in a file "demo_error.c", the command "./picoc -s 
demo_error.c" will run it.



What is the expected output? What do you see instead?
Expected output:
Here's a print statement before quitting.
returning; there should be no further output.

Actual output:
Here's a print statement before quitting.
returning; there should be no further output.
case 0: value=5


Rather than returning from the if block, the return statement is jumping into 
the case 0 switch block, as evidenced by which printf's do and do not run.

Changing the order of cases in the switch block have no effect; the case 0 
printf is still executed.

Changing the value of "value" also has no effect.


What version of the product are you using? On what operating system?
I've reproduced this problem using version 603, on Linux and OS X.


Original issue reported on code.google.com by m...@heilpern.com on 27 Feb 2014 at 5:17

@GoogleCodeExporter
Copy link
Author

I have encountered this issue too with version 603 on Windows 7, compiled with 
MS Visual Studio.

Original comment by christop...@gmail.com on 28 Feb 2014 at 2:10

@GoogleCodeExporter
Copy link
Author

I think the bug is somewhere in the function ParseStatement() in the processing 
of a switch token.
I found a fix, not sure if is the correct way to do by replacing line 809:
ParseBlock(Parser, TRUE, OldMode != RunModeSkip);
by:
ParseBlock(Parser, TRUE, (OldMode != RunModeSkip) && (OldMode != 
RunModeReturn));

Original comment by christop...@gmail.com on 28 Feb 2014 at 2:20

@GoogleCodeExporter
Copy link
Author

Thanks Christopher. I've applied your fix and it passes the regression tests.

Fixed in r606.

Original comment by zik.sale...@gmail.com on 1 Mar 2014 at 4:25

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant