Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
caf36699
Commit
caf36699
authored
Mar 22, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: fix up warnings with -Wwrite-strings.
Be a little more careful with const.
parent
e2fc21e5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
44 additions
and
29 deletions
+44
-29
tools/ccanlint/ccanlint.c
tools/ccanlint/ccanlint.c
+11
-5
tools/ccanlint/ccanlint.h
tools/ccanlint/ccanlint.h
+1
-1
tools/ccanlint/tests/examples_compile.c
tools/ccanlint/tests/examples_compile.c
+15
-10
tools/ccanlint/tests/examples_exist.c
tools/ccanlint/tests/examples_exist.c
+3
-1
tools/ccanlint/tests/examples_run.c
tools/ccanlint/tests/examples_run.c
+4
-3
tools/configurator/configurator.c
tools/configurator/configurator.c
+5
-4
tools/depends.c
tools/depends.c
+1
-1
tools/tools.c
tools/tools.c
+3
-3
tools/tools.h
tools/tools.h
+1
-1
No files found.
tools/ccanlint/ccanlint.c
View file @
caf36699
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include <ccan/opt/opt.h>
#include <ccan/opt/opt.h>
#include <ccan/foreach/foreach.h>
#include <ccan/foreach/foreach.h>
#include <ccan/grab_file/grab_file.h>
#include <ccan/grab_file/grab_file.h>
#include <ccan/cast/cast.h>
int
verbose
=
0
;
int
verbose
=
0
;
static
LIST_HEAD
(
compulsory_tests
);
static
LIST_HEAD
(
compulsory_tests
);
...
@@ -43,8 +44,8 @@ static struct btree *info_exclude;
...
@@ -43,8 +44,8 @@ static struct btree *info_exclude;
static
unsigned
int
timeout
;
static
unsigned
int
timeout
;
/* These are overridden at runtime if we can find config.h */
/* These are overridden at runtime if we can find config.h */
char
*
compiler
=
NULL
;
c
onst
c
har
*
compiler
=
NULL
;
char
*
cflags
=
NULL
;
c
onst
c
har
*
cflags
=
NULL
;
const
char
*
config_header
;
const
char
*
config_header
;
...
@@ -301,7 +302,7 @@ static void init_tests(void)
...
@@ -301,7 +302,7 @@ static void init_tests(void)
}
}
}
}
static
int
show_tmpdir
(
char
*
dir
)
static
int
show_tmpdir
(
c
onst
c
har
*
dir
)
{
{
printf
(
"You can find ccanlint working files in '%s'
\n
"
,
dir
);
printf
(
"You can find ccanlint working files in '%s'
\n
"
,
dir
);
return
0
;
return
0
;
...
@@ -576,6 +577,11 @@ static void read_config_header(void)
...
@@ -576,6 +577,11 @@ static void read_config_header(void)
compiler
=
CCAN_CFLAGS
;
compiler
=
CCAN_CFLAGS
;
}
}
static
char
*
opt_set_const_charp
(
const
char
*
arg
,
const
char
**
p
)
{
return
opt_set_charp
(
arg
,
cast_const2
(
char
**
,
p
));
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
bool
summary
=
false
;
bool
summary
=
false
;
...
@@ -613,9 +619,9 @@ int main(int argc, char *argv[])
...
@@ -613,9 +619,9 @@ int main(int argc, char *argv[])
opt_register_arg
(
"--target <testname>"
,
opt_set_charp
,
opt_register_arg
(
"--target <testname>"
,
opt_set_charp
,
NULL
,
&
target
,
NULL
,
&
target
,
"only run one test (and its prerequisites)"
);
"only run one test (and its prerequisites)"
);
opt_register_arg
(
"--compiler <compiler>"
,
opt_set_charp
,
opt_register_arg
(
"--compiler <compiler>"
,
opt_set_c
onst_c
harp
,
NULL
,
&
compiler
,
"set the compiler"
);
NULL
,
&
compiler
,
"set the compiler"
);
opt_register_arg
(
"--cflags <flags>"
,
opt_set_charp
,
opt_register_arg
(
"--cflags <flags>"
,
opt_set_c
onst_c
harp
,
NULL
,
&
cflags
,
"set the compiler flags"
);
NULL
,
&
cflags
,
"set the compiler flags"
);
opt_register_noarg
(
"-?|-h|--help"
,
opt_usage_and_exit
,
opt_register_noarg
(
"-?|-h|--help"
,
opt_usage_and_exit
,
"
\n
A program for checking and guiding development"
"
\n
A program for checking and guiding development"
...
...
tools/ccanlint/ccanlint.h
View file @
caf36699
...
@@ -222,7 +222,7 @@ extern bool safe_mode;
...
@@ -222,7 +222,7 @@ extern bool safe_mode;
extern
const
char
*
ccan_dir
;
extern
const
char
*
ccan_dir
;
/* Compiler and CFLAGS, from config.h if available. */
/* Compiler and CFLAGS, from config.h if available. */
extern
char
*
compiler
,
*
cflags
;
extern
c
onst
c
har
*
compiler
,
*
cflags
;
/* Contents of config.h (or NULL if not found) */
/* Contents of config.h (or NULL if not found) */
extern
const
char
*
config_header
;
extern
const
char
*
config_header
;
...
...
tools/ccanlint/tests/examples_compile.c
View file @
caf36699
#include <tools/ccanlint/ccanlint.h>
#include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h>
#include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/talloc/talloc.h>
#include <ccan/cast/cast.h>
#include <ccan/str/str.h>
#include <ccan/str/str.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
...
@@ -193,35 +194,38 @@ static bool looks_internal(char **lines, char **why)
...
@@ -193,35 +194,38 @@ static bool looks_internal(char **lines, char **why)
/* The winners. */
/* The winners. */
if
(
strstarts
(
line
,
"if"
)
&&
len
==
2
)
{
if
(
strstarts
(
line
,
"if"
)
&&
len
==
2
)
{
*
why
=
"starts with if"
;
*
why
=
cast_const
(
char
*
,
"starts with if"
)
;
return
true
;
return
true
;
}
}
if
(
strstarts
(
line
,
"for"
)
&&
len
==
3
)
{
if
(
strstarts
(
line
,
"for"
)
&&
len
==
3
)
{
*
why
=
"starts with for"
;
*
why
=
cast_const
(
char
*
,
"starts with for"
)
;
return
true
;
return
true
;
}
}
if
(
strstarts
(
line
,
"while"
)
&&
len
==
5
)
{
if
(
strstarts
(
line
,
"while"
)
&&
len
==
5
)
{
*
why
=
"starts with while"
;
*
why
=
cast_const
(
char
*
,
"starts with while"
)
;
return
true
;
return
true
;
}
}
if
(
strstarts
(
line
,
"do"
)
&&
len
==
2
)
{
if
(
strstarts
(
line
,
"do"
)
&&
len
==
2
)
{
*
why
=
"starts with do"
;
*
why
=
cast_const
(
char
*
,
"starts with do"
)
;
return
true
;
return
true
;
}
}
/* The losers. */
/* The losers. */
if
(
strstarts
(
line
,
"#include"
))
{
if
(
strstarts
(
line
,
"#include"
))
{
*
why
=
"starts with #include"
;
*
why
=
cast_const
(
char
*
,
"starts with #include"
)
;
return
false
;
return
false
;
}
}
if
(
last_ended
&&
strchr
(
line
,
'('
))
{
if
(
last_ended
&&
strchr
(
line
,
'('
))
{
if
(
strstarts
(
line
,
"static"
))
{
if
(
strstarts
(
line
,
"static"
))
{
*
why
=
"starts with static and contains ("
;
*
why
=
cast_const
(
char
*
,
"starts with static"
" and contains ("
);
return
false
;
return
false
;
}
}
if
(
strends
(
line
,
")"
))
{
if
(
strends
(
line
,
")"
))
{
*
why
=
"contains ( and ends with )"
;
*
why
=
cast_const
(
char
*
,
"contains ( and ends with )"
);
return
false
;
return
false
;
}
}
}
}
...
@@ -229,7 +233,8 @@ static bool looks_internal(char **lines, char **why)
...
@@ -229,7 +233,8 @@ static bool looks_internal(char **lines, char **why)
/* Single identifier then operator == inside function. */
/* Single identifier then operator == inside function. */
if
(
last_ended
&&
len
if
(
last_ended
&&
len
&&
cispunct
(
line
[
len
+
strspn
(
line
+
len
,
" "
)]))
{
&&
cispunct
(
line
[
len
+
strspn
(
line
+
len
,
" "
)]))
{
*
why
=
"starts with identifier then punctuation"
;
*
why
=
cast_const
(
char
*
,
"starts with identifier"
" then punctuation"
);
return
true
;
return
true
;
}
}
...
@@ -239,7 +244,7 @@ static bool looks_internal(char **lines, char **why)
...
@@ -239,7 +244,7 @@ static bool looks_internal(char **lines, char **why)
}
}
/* No idea... Say yes? */
/* No idea... Say yes? */
*
why
=
"gave no clues"
;
*
why
=
cast_const
(
char
*
,
"gave no clues"
)
;
return
true
;
return
true
;
}
}
...
@@ -521,7 +526,7 @@ static void build_examples(struct manifest *m, bool keep,
...
@@ -521,7 +526,7 @@ static void build_examples(struct manifest *m, bool keep,
bool
res
[
3
];
bool
res
[
3
];
unsigned
num
,
j
;
unsigned
num
,
j
;
char
**
lines
[
3
];
char
**
lines
[
3
];
char
*
error
;
c
onst
c
har
*
error
;
score
->
total
++
;
score
->
total
++
;
...
...
tools/ccanlint/tests/examples_exist.c
View file @
caf36699
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include <tools/tools.h>
#include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h>
#include <ccan/str/str.h>
#include <ccan/cast/cast.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <fcntl.h>
...
@@ -48,7 +49,8 @@ static char *add_example(struct manifest *m, struct ccan_file *source,
...
@@ -48,7 +49,8 @@ static char *add_example(struct manifest *m, struct ccan_file *source,
!=
strlen
(
example
->
lines
[
i
])
!=
strlen
(
example
->
lines
[
i
])
||
write
(
fd
,
"
\n
"
,
1
)
!=
1
)
{
||
write
(
fd
,
"
\n
"
,
1
)
!=
1
)
{
close
(
fd
);
close
(
fd
);
return
"Failure writing to temporary file"
;
return
cast_const
(
char
*
,
"Failure writing to temporary file"
);
}
}
}
}
close
(
fd
);
close
(
fd
);
...
...
tools/ccanlint/tests/examples_run.c
View file @
caf36699
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include <ccan/talloc/talloc.h>
#include <ccan/talloc/talloc.h>
#include <ccan/foreach/foreach.h>
#include <ccan/foreach/foreach.h>
#include <ccan/str/str.h>
#include <ccan/str/str.h>
#include <ccan/cast/cast.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <fcntl.h>
...
@@ -116,7 +117,7 @@ static char *find_expect(struct ccan_file *file,
...
@@ -116,7 +117,7 @@ static char *find_expect(struct ccan_file *file,
foreach_ptr
(
fmt
,
"outputs '%s'"
,
"outputs
\"
%s
\"
"
)
{
foreach_ptr
(
fmt
,
"outputs '%s'"
,
"outputs
\"
%s
\"
"
)
{
if
(
scan_for
(
file
,
p
,
fmt
,
&
expect
))
{
if
(
scan_for
(
file
,
p
,
fmt
,
&
expect
))
{
*
input
=
""
;
*
input
=
cast_const
(
char
*
,
""
)
;
*
exact
=
true
;
*
exact
=
true
;
return
expect
;
return
expect
;
}
}
...
@@ -173,7 +174,7 @@ static char *find_expect(struct ccan_file *file,
...
@@ -173,7 +174,7 @@ static char *find_expect(struct ccan_file *file,
"outputs
\"
%s
\"
"
,
"outputs
\"
%s
\"
"
,
"outputs %s"
)
{
"outputs %s"
)
{
if
(
scan_for
(
file
,
p
,
fmt
,
&
expect
))
{
if
(
scan_for
(
file
,
p
,
fmt
,
&
expect
))
{
*
input
=
""
;
*
input
=
cast_const
(
char
*
,
""
)
;
*
exact
=
true
;
*
exact
=
true
;
return
expect
;
return
expect
;
}
}
...
@@ -184,7 +185,7 @@ static char *find_expect(struct ccan_file *file,
...
@@ -184,7 +185,7 @@ static char *find_expect(struct ccan_file *file,
"output contains
\"
%s
\"
"
,
"output contains
\"
%s
\"
"
,
"output contains %s"
)
{
"output contains %s"
)
{
if
(
scan_for
(
file
,
p
,
fmt
,
&
expect
))
{
if
(
scan_for
(
file
,
p
,
fmt
,
&
expect
))
{
*
input
=
""
;
*
input
=
cast_const
(
char
*
,
""
)
;
*
exact
=
false
;
*
exact
=
false
;
return
expect
;
return
expect
;
}
}
...
...
tools/configurator/configurator.c
View file @
caf36699
...
@@ -92,7 +92,7 @@ static struct test tests[] = {
...
@@ -92,7 +92,7 @@ static struct test tests[] = {
{
"HAVE_BYTESWAP_H"
,
OUTSIDE_MAIN
,
NULL
,
{
"HAVE_BYTESWAP_H"
,
OUTSIDE_MAIN
,
NULL
,
"#include <byteswap.h>
\n
"
},
"#include <byteswap.h>
\n
"
},
{
"HAVE_COMPOUND_LITERALS"
,
INSIDE_MAIN
,
NULL
,
{
"HAVE_COMPOUND_LITERALS"
,
INSIDE_MAIN
,
NULL
,
"
char **foo = (char *[]) {
\"
x
\"
,
\"
y
\"
,
\"
z
\"
};
\n
"
"
int *foo = (int[]) { 1, 2, 3, 4
};
\n
"
"return foo[0] ? 0 : 1;"
},
"return foo[0] ? 0 : 1;"
},
{
"HAVE_FOR_LOOP_DECLARATION"
,
INSIDE_MAIN
,
NULL
,
{
"HAVE_FOR_LOOP_DECLARATION"
,
INSIDE_MAIN
,
NULL
,
"for (int i = 0; i < argc; i++) { return 0; };
\n
"
"for (int i = 0; i < argc; i++) { return 0; };
\n
"
...
@@ -208,7 +208,7 @@ static char *run(const char *cmd, int *exitstatus)
...
@@ -208,7 +208,7 @@ static char *run(const char *cmd, int *exitstatus)
return
ret
;
return
ret
;
}
}
static
char
*
connect_args
(
char
*
argv
[],
const
char
*
extra
)
static
char
*
connect_args
(
c
onst
c
har
*
argv
[],
const
char
*
extra
)
{
{
unsigned
int
i
,
len
=
strlen
(
extra
)
+
1
;
unsigned
int
i
,
len
=
strlen
(
extra
)
+
1
;
char
*
ret
;
char
*
ret
;
...
@@ -325,11 +325,12 @@ static bool run_test(const char *cmd, struct test *test)
...
@@ -325,11 +325,12 @@ static bool run_test(const char *cmd, struct test *test)
return
test
->
answer
;
return
test
->
answer
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
c
onst
c
har
*
argv
[])
{
{
char
*
cmd
;
char
*
cmd
;
char
*
default_args
[]
=
{
""
,
DEFAULT_COMPILER
,
DEFAULT_FLAGS
,
NULL
};
unsigned
int
i
;
unsigned
int
i
;
const
char
*
default_args
[]
=
{
""
,
DEFAULT_COMPILER
,
DEFAULT_FLAGS
,
NULL
};
if
(
argc
>
1
)
{
if
(
argc
>
1
)
{
if
(
strcmp
(
argv
[
1
],
"--help"
)
==
0
)
{
if
(
strcmp
(
argv
[
1
],
"--help"
)
==
0
)
{
...
...
tools/depends.c
View file @
caf36699
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#include <errno.h>
#include <errno.h>
static
char
**
__attribute__
((
format
(
printf
,
2
,
3
)))
static
char
**
__attribute__
((
format
(
printf
,
2
,
3
)))
lines_from_cmd
(
const
void
*
ctx
,
char
*
format
,
...)
lines_from_cmd
(
const
void
*
ctx
,
c
onst
c
har
*
format
,
...)
{
{
va_list
ap
;
va_list
ap
;
char
*
cmd
,
*
buffer
;
char
*
cmd
,
*
buffer
;
...
...
tools/tools.c
View file @
caf36699
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
#include <assert.h>
#include <assert.h>
#include "tools.h"
#include "tools.h"
static
char
*
tmpdir
=
NULL
;
static
c
onst
c
har
*
tmpdir
=
NULL
;
bool
tools_verbose
=
false
;
bool
tools_verbose
=
false
;
/* Ten minutes. */
/* Ten minutes. */
...
@@ -176,7 +176,7 @@ bool run_command(const void *ctx, unsigned int *time_ms, char **output,
...
@@ -176,7 +176,7 @@ bool run_command(const void *ctx, unsigned int *time_ms, char **output,
return
false
;
return
false
;
}
}
static
int
unlink_all
(
char
*
dir
)
static
int
unlink_all
(
c
onst
c
har
*
dir
)
{
{
char
cmd
[
strlen
(
dir
)
+
sizeof
(
"rm -rf "
)];
char
cmd
[
strlen
(
dir
)
+
sizeof
(
"rm -rf "
)];
sprintf
(
cmd
,
"rm -rf %s"
,
dir
);
sprintf
(
cmd
,
"rm -rf %s"
,
dir
);
...
@@ -187,7 +187,7 @@ static int unlink_all(char *dir)
...
@@ -187,7 +187,7 @@ static int unlink_all(char *dir)
return
0
;
return
0
;
}
}
char
*
temp_dir
(
const
void
*
ctx
)
c
onst
c
har
*
temp_dir
(
const
void
*
ctx
)
{
{
/* For first call, create dir. */
/* For first call, create dir. */
while
(
!
tmpdir
)
{
while
(
!
tmpdir
)
{
...
...
tools/tools.h
View file @
caf36699
...
@@ -43,7 +43,7 @@ bool PRINTF_FMT(4,5) run_command(const void *ctx,
...
@@ -43,7 +43,7 @@ bool PRINTF_FMT(4,5) run_command(const void *ctx,
const
char
*
fmt
,
...);
const
char
*
fmt
,
...);
char
*
run_with_timeout
(
const
void
*
ctx
,
const
char
*
cmd
,
char
*
run_with_timeout
(
const
void
*
ctx
,
const
char
*
cmd
,
bool
*
ok
,
unsigned
*
timeout_ms
);
bool
*
ok
,
unsigned
*
timeout_ms
);
char
*
temp_dir
(
const
void
*
ctx
);
c
onst
c
har
*
temp_dir
(
const
void
*
ctx
);
bool
move_file
(
const
char
*
oldname
,
const
char
*
newname
);
bool
move_file
(
const
char
*
oldname
,
const
char
*
newname
);
/* From compile.c.
/* From compile.c.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment