public inbox for linux-audit@redhat.com
 help / color / mirror / Atom feed
From: Tyler Hicks <tyhicks@canonical.com>
To: Steve Grubb <sgrubb@redhat.com>
Cc: linux-audit@redhat.com
Subject: [PATCH 3/3] Fix discards 'const' qualifier from pointer target type warnings
Date: Fri,  8 Feb 2013 19:12:35 -0800	[thread overview]
Message-ID: <1360379555-1910-4-git-send-email-tyhicks@canonical.com> (raw)
In-Reply-To: <1360379555-1910-1-git-send-email-tyhicks@canonical.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 <tyhicks@canonical.com>
---
 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<len; i+=2) {
-		*ptr = x2c((unsigned char *)&str[i]);
-		ptr++;
+		*strptr = x2c((unsigned char *)&str[i]);
+		strptr++;
 	}
-	*ptr = 0;
+	*strptr = 0;
 	return str;
 }
 
diff --git a/src/ausearch-options.c b/src/ausearch-options.c
index 769d8fa..06a85bb 100644
--- a/src/ausearch-options.c
+++ b/src/ausearch-options.c
@@ -68,7 +68,7 @@ const char *event_vmname = NULL;
 report_t report_format = RPT_DEFAULT;
 ilist *event_type;
 
-const slist *event_node_list = NULL;
+slist *event_node_list = NULL;
 
 struct nv_pair {
     int        value;
-- 
1.7.10.4

  parent reply	other threads:[~2013-02-09  3:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-09  3:12 [PATCH 0/3] Fix userspace audit compiler warnings Tyler Hicks
2013-02-09  3:12 ` [PATCH 1/3] Don't ignore the return value of asprintf() Tyler Hicks
2013-02-09 16:50   ` Steve Grubb
2013-02-09  3:12 ` [PATCH 2/3] Fix Wunused-return warnings Tyler Hicks
2013-02-09 16:57   ` Steve Grubb
2013-02-09 18:35     ` Tyler Hicks
2013-02-09  3:12 ` Tyler Hicks [this message]
2013-02-09 17:22   ` [PATCH 3/3] Fix discards 'const' qualifier from pointer target type warnings Steve Grubb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1360379555-1910-4-git-send-email-tyhicks@canonical.com \
    --to=tyhicks@canonical.com \
    --cc=linux-audit@redhat.com \
    --cc=sgrubb@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox