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:
+7
-9
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user