]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
replaced with grub_strchrsub function
authorBVK Chaitanya <bvk.groups@gmail.com>
Thu, 25 Nov 2010 13:26:20 +0000 (18:56 +0530)
committerBVK Chaitanya <bvk.groups@gmail.com>
Thu, 25 Nov 2010 13:26:20 +0000 (18:56 +0530)
grub-core/commands/menuentry.c
grub-core/lib/legacy_parse.c
grub-core/script/script.c
include/grub/misc.h
include/grub/script_sh.h

index f64378724510bd6c75f55079b2e6ec65ca4d7827..c0743d1ed51ee26da074ab656b07727fcebd2210 100644 (file)
@@ -228,7 +228,7 @@ setparams_prefix (int argc, char **args)
     {
       *p++ = ' ';
       *p++ = '\'';
-      p = grub_script_escape_squotes (p, args[j], grub_strlen (args[j]));
+      p = grub_strchrsub (p, args[j], '\'', "'\\''");
       *p++ = '\'';
     }
   *p++ = '\n';
index 8fe60b03d5f3e03940b691301e7e62a0bb517fd4..d3a133591c2de801cec0628f2d752a9d46833c92 100644 (file)
@@ -323,16 +323,23 @@ struct legacy_command legacy_commands[] =
 char *
 grub_legacy_escape (const char *in, grub_size_t len)
 {
-  const char *ptr;
+  char saved;
+  char *ptr;
   char *outptr;
   int overhead = 0;
-  for (ptr = in; ptr < in + len && *ptr; ptr++)
+
+  for (ptr = (char*)in; ptr < in + len && *ptr; ptr++)
     if (*ptr == '\'')
       overhead += 3;
   outptr = grub_malloc (ptr - in + overhead + 1);
   if (!outptr)
     return NULL;
-  grub_script_escape_squotes (outptr, in, len);
+
+  ptr = (char*)in;
+  saved = ptr[len];
+  ptr[len] = '\0';
+  grub_strchrsub (outptr, in, '\'', "'\\''");
+  ptr[len] = saved;
   return outptr;
 }
 
index 45c3222b2581b1e66dafa6af04bc31dfee66c4e1..ad30183577e50203551560748758a1aa16f9bd91 100644 (file)
 #include <grub/parser.h>
 #include <grub/mm.h>
 
-/* Escape single quotes in first `len' characters of `in' into a GRUB
-   script argument form into `out'; return address of the end in
-   `out'. */
-char *
-grub_script_escape_squotes (char *out, const char *in, grub_size_t len)
-{
-  while (*in && len--)
-    {
-      *out++ = *in;
-      if (*in == '\'')
-       {
-         *out++ = '\\';
-         *out++ = '\'';
-         *out++ = '\'';
-       }
-      in++;
-    }
-  *out = '\0';
-  return out;
-}
-
 /* It is not possible to deallocate the memory when a syntax error was
    found.  Because of that it is required to keep track of all memory
    allocations.  The memory is freed in case of an error, or assigned
index 27f15e44a6f9fd37681084cbc932a9c16a46f15c..4980281a6bf6f888c87ad9e01732847abccfb0d7 100644 (file)
@@ -193,6 +193,26 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n)
   return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
 }
 
+/* Replace all `ch' characters of `input' with `with' and copy the
+   result into `output'; return address of the end in `output'. */
+static inline char *
+grub_strchrsub (char *output, const char *input, char ch, const char *with)
+{
+  grub_size_t grub_strlen (const char *s);
+  while (*input)
+    {
+      if (*input == ch)
+       {
+         grub_strcpy (output, with);
+         output += grub_strlen (with);
+         input++;
+         continue;
+       }
+      *output++ = *input++;
+    }
+  *output = '\0';
+  return output;
+}
 
 unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base);
 unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base);
index f5dcd881e6a43aaf59f5e80beb580adc32dc361f..6d31fca5ae89e24a729b18fe1578b5d3b26de2aa 100644 (file)
@@ -382,9 +382,6 @@ grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *c
 grub_err_t
 grub_normal_parse_line (char *line, grub_reader_getline_t getline);
 
-char *
-grub_script_escape_squotes (char *out, const char *in, grub_size_t len);
-
 static inline struct grub_script *
 grub_script_ref (struct grub_script *script)
 {