From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [B.A.T.M.A.N.] [PATCH 03/11] batctl: Avoid assigning const buffer to non-const pointer
Date: Tue, 10 Sep 2013 23:11:54 +0200 [thread overview]
Message-ID: <1378847522-13776-4-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1378847522-13776-1-git-send-email-sven@narfation.org>
Strings in C are tried to be saved in the .rodata by the compiler/linker. This
section is readonly as the name suggests. Pointer to these strings should
therefore be const.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
functions.c | 8 +++++---
functions.h | 5 +++--
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/functions.c b/functions.c
index 2a2f392..bd4da59 100644
--- a/functions.c
+++ b/functions.c
@@ -124,7 +124,8 @@ int file_exists(const char *fpath)
return stat(fpath, &st) == 0;
}
-static void file_open_problem_dbg(char *dir, char *fname, char *full_path)
+static void file_open_problem_dbg(const char *dir, const char *fname,
+ const char *full_path)
{
const char **ptr;
struct stat st;
@@ -162,7 +163,7 @@ static void file_open_problem_dbg(char *dir, char *fname, char *full_path)
}
}
-int read_file(char *dir, char *fname, int read_opt,
+int read_file(const char *dir, const char *fname, int read_opt,
float orig_timeout, float watch_interval, size_t header_lines)
{
struct ether_addr *mac_addr;
@@ -296,7 +297,8 @@ out:
return res;
}
-int write_file(char *dir, char *fname, char *arg1, char *arg2)
+int write_file(const char *dir, const char *fname, const char *arg1,
+ const char *arg2)
{
int fd = 0, res = EXIT_FAILURE;
char full_path[500];
diff --git a/functions.h b/functions.h
index d88c494..f9c8191 100644
--- a/functions.h
+++ b/functions.h
@@ -34,9 +34,10 @@ char *ether_ntoa_long(const struct ether_addr *addr);
char *get_name_by_macaddr(struct ether_addr *mac_addr, int read_opt);
char *get_name_by_macstr(char *mac_str, int read_opt);
int file_exists(const char *fpath);
-int read_file(char *dir, char *path, int read_opt,
+int read_file(const char *dir, const char *path, int read_opt,
float orig_timeout, float watch_interval, size_t header_lines);
-int write_file(char *dir, char *fname, char *arg1, char *arg2);
+int write_file(const char *dir, const char *fname, const char *arg1,
+ const char *arg2);
struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac);
struct ether_addr *resolve_mac(const char *asc);
--
1.8.4.rc3
next prev parent reply other threads:[~2013-09-10 21:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-10 21:11 [B.A.T.M.A.N.] batctl: Debian patches for 2013.3.0-2 Sven Eckelmann
2013-09-10 21:11 ` [B.A.T.M.A.N.] [PATCH 01/11] batctl: Fix possible buffer overflow when using strncat Sven Eckelmann
2013-09-11 10:49 ` Marek Lindner
2013-09-10 21:11 ` [B.A.T.M.A.N.] [PATCH 02/11] batctl: Fix inconsistent use of _GNU_SOURCE Sven Eckelmann
2013-09-11 10:53 ` Marek Lindner
2013-09-10 21:11 ` Sven Eckelmann [this message]
2013-09-11 10:56 ` [B.A.T.M.A.N.] [PATCH 03/11] batctl: Avoid assigning const buffer to non-const pointer Marek Lindner
2013-09-10 21:11 ` [B.A.T.M.A.N.] [PATCH 04/11] batctl: Mark all local functions as static Sven Eckelmann
2013-09-11 10:58 ` Marek Lindner
2013-09-10 21:11 ` [B.A.T.M.A.N.] [PATCH 05/11] batctl: Add include guards to avoid redundant declarations or include loops Sven Eckelmann
2013-09-11 11:33 ` Marek Lindner
2013-09-10 21:11 ` [B.A.T.M.A.N.] [PATCH 06/11] batctl: Remove legacy types u64 and caddr_t Sven Eckelmann
2013-09-13 10:51 ` Marek Lindner
2013-09-10 21:11 ` [B.A.T.M.A.N.] [PATCH 07/11] batctl: Add missing includes and remove unused includes Sven Eckelmann
2013-09-10 21:11 ` [B.A.T.M.A.N.] [PATCH 08/11] batctl: Fix error handling jump in interface when batadv not loaded Sven Eckelmann
2013-09-13 10:58 ` Marek Lindner
2013-09-10 21:12 ` [B.A.T.M.A.N.] [PATCH 09/11] batctl: Fix type of new neighbor buffer in _seqno_trace_neigh_add Sven Eckelmann
2013-09-13 11:22 ` Marek Lindner
2013-09-10 21:12 ` [B.A.T.M.A.N.] [PATCH 10/11] batctl: Don't fail rebuild when header is removed Sven Eckelmann
2013-09-13 11:24 ` Marek Lindner
2013-09-10 21:12 ` [B.A.T.M.A.N.] [PATCH 11/11] batctl: Don't use hyphen for parameter in manpage Sven Eckelmann
2013-09-13 11:26 ` Marek Lindner
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=1378847522-13776-4-git-send-email-sven@narfation.org \
--to=sven@narfation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/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