Meco Man hace 4 años
padre
commit
790486cf57
Se han modificado 3 ficheros con 7 adiciones y 29 borrados
  1. 5 2
      vi.c
  2. 1 26
      vi_utils.c
  3. 1 1
      vi_utils.h

+ 5 - 2
vi.c

@@ -542,7 +542,7 @@ static int vi_main(int argc, char **argv)
             // fall through
         default:
             bb_show_usage();
-            free(ptr_to_globals);
+            FREE_PTR_TO_GLOBALS(); // RT-Thread team added
             return 1;
         }
     }
@@ -568,6 +568,8 @@ static int vi_main(int argc, char **argv)
 #ifndef RT_USING_POSIX
     wait_read(STDIN_FILENO, status_buffer, STATUS_BUFFER_LEN, 0);
 #endif
+
+    /* RT-Thread team added */
     free(text);
     free(screen);
     free(current_filename);
@@ -577,8 +579,9 @@ static int vi_main(int argc, char **argv)
 #if ENABLE_FEATURE_VI_SEARCH
     free(last_search_pattern);
 #endif
-    free(ptr_to_globals);
+    FREE_PTR_TO_GLOBALS();
     fflush_all();
+
     return 0;
 }
 

+ 1 - 26
vi_utils.c

@@ -21,32 +21,6 @@ int index_in_strings(const char *strings, const char *key)
 }
 
 #ifdef VI_ENABLE_COLON
-// Die if we can't allocate n+1 bytes (space for the null terminator) and copy
-// the (possibly truncated to length n) string into it.
-char* xstrndup(const char *s, int n)
-{
-    int m;
-    char *t;
-
-    if (ENABLE_DEBUG && s == NULL)
-        bb_simple_error_msg_and_die("xstrndup bug");
-
-    /* We can just xmalloc(n+1) and strncpy into it, */
-    /* but think about xstrndup("abc", 10000) wastage! */
-    m = n;
-    t = (char*) s;
-    while (m) {
-        if (!*t) break;
-        m--;
-        t++;
-    }
-    n -= m;
-    t = xmalloc(n + 1);
-    t[n] = '\0';
-
-    return memcpy(t, s, n);
-}
-
 char* last_char_is(const char *s, int c)
 {
     if (s && *s) {
@@ -71,6 +45,7 @@ void *memrchr(const void* ptr, int ch, size_t pos)
     }
     return (*end == ch)?(end):(NULL);
 }
+
 int isblank(int ch)
 {
     if (ch == ' ' || ch == '\t')

+ 1 - 1
vi_utils.h

@@ -23,6 +23,7 @@
 #define xmalloc malloc
 #define xrealloc realloc
 #define xstrdup strdup
+#define xstrndup strndup
 #define bb_putchar putchar
 #define bb_strtou strtoul
 #define bb_simple_error_msg_and_die(...) printf(__VA_ARGS__)
@@ -355,7 +356,6 @@ int isatty (int  fd);
 char* strchrnul(const char *s, int c);
 #endif
 #ifdef VI_ENABLE_COLON
-char* xstrndup(const char *s, int n);
 char* last_char_is(const char *s, int c);
 #endif