Introduce FIX_STRINGA, use it fpcrtl_pos
authorunc0rr
Wed, 07 Nov 2018 19:43:17 +0100
changeset 14180 0aeea29ef890
parent 14179 ddc77c3b1823
child 14181 c24a76f131d6
Introduce FIX_STRINGA, use it fpcrtl_pos
project_files/hwc/rtl/misc.h
project_files/hwc/rtl/system.c
--- 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);\
--- 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);