bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/5] arrayfunc: constify array names


From: Mike Frysinger
Subject: [PATCH 3/5] arrayfunc: constify array names
Date: Thu, 11 Aug 2016 20:30:48 +0800

Noticed when looking into segfault.  The "discarding const qualifier"
warning always makes me worried as it tends to come from bad code.
---
 arrayfunc.c | 18 ++++++++++--------
 arrayfunc.h | 12 ++++++------
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/arrayfunc.c b/arrayfunc.c
index fb87112281d8..eca6e03a642e 100644
--- a/arrayfunc.c
+++ b/arrayfunc.c
@@ -48,7 +48,7 @@ static SHELL_VAR *assign_array_element_internal 
__P((SHELL_VAR *, char *, char *
 
 static char *quote_assign __P((const char *));
 static void quote_array_assignment_chars __P((WORD_LIST *));
-static char *array_value_internal __P((char *, int, int, int *, arrayind_t *));
+static char *array_value_internal __P((const char *, int, int, int *, 
arrayind_t *));
 
 /* Standard error message to use when encountering an invalid array subscript 
*/
 const char * const bash_badsub_errmsg = N_("bad array subscript");
@@ -881,7 +881,7 @@ print_assoc_assignment (var, quoted)
 /* Return 1 if NAME is a properly-formed array reference v[sub]. */
 int
 valid_array_reference (name, flags)
-     char *name;
+     const char *name;
      int flags;
 {
   char *t;
@@ -948,7 +948,8 @@ array_expand_index (var, s, len)
    in *LENP.  This returns newly-allocated memory. */
 char *
 array_variable_name (s, subp, lenp)
-     char *s, **subp;
+     const char *s;
+     char **subp;
      int *lenp;
 {
   char *t, *ret;
@@ -992,7 +993,8 @@ array_variable_name (s, subp, lenp)
    If LENP is non-null, the length of the subscript is returned in *LENP. */
 SHELL_VAR *
 array_variable_part (s, subp, lenp)
-     char *s, **subp;
+     const char *s;
+     char **subp;
      int *lenp;
 {
   char *t;
@@ -1029,7 +1031,7 @@ array_variable_part (s, subp, lenp)
    reference is name[@], and 0 otherwise. */
 static char *
 array_value_internal (s, quoted, flags, rtype, indp)
-     char *s;
+     const char *s;
      int quoted, flags, *rtype;
      arrayind_t *indp;
 {
@@ -1149,7 +1151,7 @@ array_value_internal (s, quoted, flags, rtype, indp)
    subscript contained in S, obeying quoting for subscripts * and @. */
 char *
 array_value (s, quoted, flags, rtype, indp)
-     char *s;
+     const char *s;
      int quoted, flags, *rtype;
      arrayind_t *indp;
 {
@@ -1162,7 +1164,7 @@ array_value (s, quoted, flags, rtype, indp)
    evaluator in expr.c. */
 char *
 get_array_value (s, flags, rtype, indp)
-     char *s;
+     const char *s;
      int flags, *rtype;
      arrayind_t *indp;
 {
@@ -1171,7 +1173,7 @@ get_array_value (s, flags, rtype, indp)
 
 char *
 array_keys (s, quoted)
-     char *s;
+     const char *s;
      int quoted;
 {
   int len;
diff --git a/arrayfunc.h b/arrayfunc.h
index 3a29a594e98e..46bf2c70f024 100644
--- a/arrayfunc.h
+++ b/arrayfunc.h
@@ -58,14 +58,14 @@ extern void print_array_assignment __P((SHELL_VAR *, int));
 extern void print_assoc_assignment __P((SHELL_VAR *, int));
 
 extern arrayind_t array_expand_index __P((SHELL_VAR *, char *, int));
-extern int valid_array_reference __P((char *, int));
-extern char *array_value __P((char *, int, int, int *, arrayind_t *));
-extern char *get_array_value __P((char *, int, int *, arrayind_t *));
+extern int valid_array_reference __P((const char *, int));
+extern char *array_value __P((const char *, int, int, int *, arrayind_t *));
+extern char *get_array_value __P((const char *, int, int *, arrayind_t *));
 
-extern char *array_keys __P((char *, int));
+extern char *array_keys __P((const char *, int));
 
-extern char *array_variable_name __P((char *, char **, int *));
-extern SHELL_VAR *array_variable_part __P((char *, char **, int *));
+extern char *array_variable_name __P((const char *, char **, int *));
+extern SHELL_VAR *array_variable_part __P((const char *, char **, int *));
 
 #else
 
-- 
2.9.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]