From 73b64e141f573e9ddbdc03a5d94dfd4df752cd0d Mon Sep 17 00:00:00 2001 From: Zeex Date: Thu, 8 Feb 2018 07:39:07 +0600 Subject: [PATCH] Fix crash when #pragma deprecated message is empty Fixes #283. --- source/compiler/sc2.c | 2 +- source/compiler/tests/CMakeLists.txt | 5 +++++ source/compiler/tests/gh_283.pwn | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 source/compiler/tests/gh_283.pwn diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 291d086..5180ae5 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1119,7 +1119,7 @@ static int command(void) if (pc_deprecate!=NULL) { char *ptr=pc_deprecate+strlen(pc_deprecate)-1; /* remove trailing whitespace */ - while (*ptr<= ' ') + while (ptr>=pc_deprecate && *ptr<= ' ') *ptr--='\0'; } else { error(103); /* insufficient memory */ diff --git a/source/compiler/tests/CMakeLists.txt b/source/compiler/tests/CMakeLists.txt index a63fdeb..a341039 100644 --- a/source/compiler/tests/CMakeLists.txt +++ b/source/compiler/tests/CMakeLists.txt @@ -40,6 +40,11 @@ set_tests_properties(unused_symbol_line_gh_252 PROPERTIES PASS_REGULAR_EXPRESSIO .*\\.pwn\\(1\\) : warning 203: symbol is never used: \\\"x\\\" ") +add_compiler_test(gh_283 ${CMAKE_CURRENT_SOURCE_DIR}/gh_283.pwn) +set_tests_properties(gh_283 PROPERTIES PASS_REGULAR_EXPRESSION "\ +.*\\.pwn\\(5\\) : warning 234: function is deprecated \\(symbol \"print\"\\)\ +") + # Crashers # # These tests simply check that the compiler doesn't crash. diff --git a/source/compiler/tests/gh_283.pwn b/source/compiler/tests/gh_283.pwn new file mode 100644 index 0000000..87645ac --- /dev/null +++ b/source/compiler/tests/gh_283.pwn @@ -0,0 +1,6 @@ +#pragma deprecated +native print(const string[]); + +main() { + print("Hello World"); +}