# HG changeset patch
# User unc0rr
# Date 1541616197 -3600
# Node ID 0aeea29ef89087d3ed5aabaad4a8875db35d7f65
# Parent  ddc77c3b1823ff9cfe95d9791bcbf3b0db79a4b1
Introduce FIX_STRINGA, use it fpcrtl_pos

diff -r ddc77c3b1823 -r 0aeea29ef890 project_files/hwc/rtl/misc.h
--- a/project_files/hwc/rtl/misc.h	Wed Nov 07 17:45:20 2018 +0100
+++ b/project_files/hwc/rtl/misc.h	Wed Nov 07 19:43:17 2018 +0100
@@ -20,7 +20,8 @@
 
 //#define     FPCRTL_DEBUG
 
-#define     FIX_STRING(s)                           (s.str[s.len == 255 ? 254 : s.len] = 0)
+#define     FIX_STRING(s)                           do { s.str[s.len == 255 ? 254 : s.len] = 0; } while (0)
+#define     FIX_STRINGA(s)                          do { s.str[s.len == MAX_ANSISTRING_LENGTH ? MAX_ANSISTRING_LENGTH - 1 : s.len] = 0; } while (0)
 //#define fpcrtl_check_string(s)     do{ if(strlen((s).str) != (s).len){ \
 //                                        printf("String %s internal inconsistency error. Length should be %d but actually is %d.\n", (s).str, strlen((s).str), (s).len); \
 //                                        assert(0);\
diff -r ddc77c3b1823 -r 0aeea29ef890 project_files/hwc/rtl/system.c
--- a/project_files/hwc/rtl/system.c	Wed Nov 07 17:45:20 2018 +0100
+++ b/project_files/hwc/rtl/system.c	Wed Nov 07 19:43:17 2018 +0100
@@ -275,6 +275,8 @@
         return 0;
     }
 
+    FIX_STRINGA(str);
+
     p = strchr(str.s + 1, c);
 
     if (p == NULL) {
@@ -298,6 +300,8 @@
     }
 
     FIX_STRING(substr);
+    FIX_STRINGA(str);
+
     str.s[str.len] = 0;
 
     p = strstr(str.s + 1, substr.str);