fix: restructure REPL loop to eliminate unreachable code after fgets failure

The original REPL loop had an if-else structure where the else branch (handling fgets failure) contained a return statement, making the code after the if-else block unreachable. This commit restructures the loop by inverting the condition: when fgets fails, the loop breaks instead of returning, allowing the subsequent wrenFreeVM call to execute. Additionally, enables CLANG_WARN_UNREACHABLE_CODE in both Debug and Release Xcode build configurations to catch similar issues in the future.
This commit is contained in:
Bob Nystrom
2015-03-22 17:26:54 +00:00
parent 295a408858
commit 4343b95c04
2 changed files with 9 additions and 9 deletions
+7 -9
View File
@@ -20,18 +20,16 @@ static int runRepl()
{
printf("> ");
if (fgets(line, MAX_LINE_LENGTH, stdin))
{
// TODO: Handle failure.
wrenInterpret(vm, "Prompt", line);
// TODO: Automatically print the result of expressions.
}
else
if (!fgets(line, MAX_LINE_LENGTH, stdin))
{
printf("\n");
return 0;
break;
}
// TODO: Handle failure.
wrenInterpret(vm, "Prompt", line);
// TODO: Automatically print the result of expressions.
}
wrenFreeVM(vm);