From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tyler Hicks Subject: [PATCH 3/3] Fix discards 'const' qualifier from pointer target type warnings Date: Fri, 8 Feb 2013 19:12:35 -0800 Message-ID: <1360379555-1910-4-git-send-email-tyhicks@canonical.com> References: <1360379555-1910-1-git-send-email-tyhicks@canonical.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1360379555-1910-1-git-send-email-tyhicks@canonical.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com To: Steve Grubb Cc: linux-audit@redhat.com List-Id: linux-audit@redhat.com The event_note_list pointer is reassigned and its members are also reassigned. It should not be declared with the const qualifier. The ptr variable, in unescape(), cannot be used to modify a string since it is initialized to the const char *buf input parameter. Rather than modifying buf, we can use ptr as a placeholder and use strndup() to allocate str. Later in the function a new, non-const pointer is used to modify str. These changes allow unescape() to still take a const char * as its input parameter. Signed-off-by: Tyler Hicks --- src/aureport-options.c | 2 +- src/ausearch-common.h | 2 +- src/ausearch-lookup.c | 16 +++++++--------- src/ausearch-options.c | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/aureport-options.c b/src/aureport-options.c index 72a1d15..2af8714 100644 --- a/src/aureport-options.c +++ b/src/aureport-options.c @@ -42,7 +42,7 @@ int force_logs = 0; /* These are for compatibility with parser */ unsigned int event_id = -1; -const slist *event_node_list = NULL; +slist *event_node_list = NULL; const char *event_key = NULL; const char *event_filename = NULL; const char *event_exe = NULL; diff --git a/src/ausearch-common.h b/src/ausearch-common.h index 2ee1f33..95c9980 100644 --- a/src/ausearch-common.h +++ b/src/ausearch-common.h @@ -35,7 +35,7 @@ extern gid_t event_gid, event_egid; extern pid_t event_pid; extern int event_exact_match; extern uid_t event_uid, event_euid, event_loginuid; -const slist *event_node_list; +slist *event_node_list; extern const char *event_comm; extern const char *event_filename; extern const char *event_hostname; diff --git a/src/ausearch-lookup.c b/src/ausearch-lookup.c index cb13003..0c8f4bf 100644 --- a/src/ausearch-lookup.c +++ b/src/ausearch-lookup.c @@ -318,7 +318,8 @@ static unsigned char x2c(unsigned char *buf) char *unescape(const char *buf) { int len, i; - char saved, *ptr = buf, *str; + char *str, *strptr; + const char *ptr = buf; /* Find the end of the name */ if (*ptr == '(') { @@ -331,10 +332,7 @@ char *unescape(const char *buf) while (isxdigit(*ptr)) ptr++; } - saved = *ptr; - *ptr = 0; - str = strdup(buf); - *ptr = saved; + str = strndup(buf, ptr - buf); if (*buf == '(') return str; @@ -347,12 +345,12 @@ char *unescape(const char *buf) free(str); return NULL; } - ptr = str; + strptr = str; for (i=0; i