summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfergus.henderson <fergushenderson@users.noreply.github.com>2008-07-31 05:40:12 +0000
committerfergus.henderson <fergushenderson@users.noreply.github.com>2008-07-31 05:40:12 +0000
commit5c3b54f86704cf9bb0af986b7cbd375dff668752 (patch)
treead9639dd4a53dfe9a33bfa82ea8cc670bd4a5a4a
parent7ac8448ba7d387c8d7c4388d3d9eba9466385769 (diff)
downloaddistcc-git-5c3b54f86704cf9bb0af986b7cbd375dff668752.tar.gz
Fix issue 10 <http://code.google.com/p/distcc/issues/detail?id=10>:
add a work-around for a spurious gcc warning. Also, add a missing check for strdup() returning NULL.
-rw-r--r--src/distcc.h1
-rw-r--r--src/filename.c30
2 files changed, 27 insertions, 4 deletions
diff --git a/src/distcc.h b/src/distcc.h
index 1a16a1c..aff2203 100644
--- a/src/distcc.h
+++ b/src/distcc.h
@@ -297,6 +297,7 @@ int dcc_is_object(const char *filename);
int dcc_source_needs_local(const char *);
char * dcc_find_extension(char *sfile);
+const char * dcc_find_extension_const(const char *sfile);
int dcc_output_from_source(const char *sfile, const char *out_extn,
char **ofile);
diff --git a/src/filename.c b/src/filename.c
index 0c6ac5f..9b23b38 100644
--- a/src/filename.c
+++ b/src/filename.c
@@ -68,6 +68,24 @@ char * dcc_find_extension(char *sfile)
return dot;
}
+/**
+ * Return a pointer to the extension, including the dot, or NULL.
+ * Same as dcc_find_extension(), but the argument and return
+ * value are both pointers to const.
+ **/
+const char * dcc_find_extension_const(const char *sfile) {
+#if 0
+ return dcc_find_extension((char *) sfile);
+#else
+ /* The following intermediate variable works around a bug in gcc 4.2.3 where
+ * for the code above gcc spuriously reports "warning: passing argument 1
+ * of 'dcc_find_extension' discards qualifiers from pointer target type",
+ * despite the explicit cast. */
+ char *sfile_nonconst = (char *)sfile;
+ return dcc_find_extension(sfile_nonconst);
+#endif
+}
+
/**
* Return a pointer to the basename of the file (everything after the
@@ -114,7 +132,11 @@ static int dcc_set_file_extension(const char *sfile,
char *dot, *o;
o = strdup(sfile);
- dot = dcc_find_extension((char *) o);
+ if (!o) {
+ rs_log_error("strdup failed (out of memory?)");
+ return EXIT_DISTCC_FAILED;
+ }
+ dot = dcc_find_extension(o);
if (!dot) {
rs_log_error("couldn't find extension in \"%s\"", o);
return EXIT_DISTCC_FAILED;
@@ -183,7 +205,7 @@ const char * dcc_preproc_exten(const char *e)
int dcc_is_preprocessed(const char *sfile)
{
const char *dot, *ext;
- dot = dcc_find_extension((char *) sfile);
+ dot = dcc_find_extension_const(sfile);
if (!dot)
return 0;
ext = dot+1;
@@ -212,7 +234,7 @@ int dcc_is_preprocessed(const char *sfile)
int dcc_is_source(const char *sfile)
{
const char *dot, *ext;
- dot = dcc_find_extension((char *) sfile);
+ dot = dcc_find_extension_const(sfile);
if (!dot)
return 0;
ext = dot+1;
@@ -260,7 +282,7 @@ int dcc_is_source(const char *sfile)
int dcc_is_object(const char *filename)
{
const char *dot;
- dot = dcc_find_extension((char *) filename);
+ dot = dcc_find_extension_const(filename);
if (!dot)
return 0;