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
d40331c7
Commit
d40331c7
authored
Oct 07, 2010
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compiler, talloc: warn if return from realloc-like functions isn't used.
This hit my doc extraction tool, so fix it!
parent
42ecd161
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
18 deletions
+40
-18
ccan/compiler/compiler.h
ccan/compiler/compiler.h
+19
-0
ccan/talloc/talloc.h
ccan/talloc/talloc.h
+7
-5
ccan/talloc/test/run.c
ccan/talloc/test/run.c
+4
-4
config.h
config.h
+10
-9
No files found.
ccan/compiler/compiler.h
View file @
d40331c7
...
...
@@ -136,4 +136,23 @@
/* If we don't know, assume it's not. */
#define IS_COMPILE_CONSTANT(expr) 0
#endif
#if HAVE_WARN_UNUSED_RESULT
/**
* WARN_UNUSED_RESULT - warn if a function return value is unused.
*
* Used to mark a function where it is extremely unlikely that the caller
* can ignore the result, eg realloc().
*
* Example:
* // buf param may be freed by this; need return value!
* static char *WARN_UNUSED_RESULT enlarge(const char *buf, unsigned *size)
* {
* return realloc(buf, (*size) *= 2);
* }
*/
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#define WARN_UNUSED_RESULT
#endif
#endif
/* CCAN_COMPILER_H */
ccan/talloc/talloc.h
View file @
d40331c7
...
...
@@ -572,7 +572,7 @@ char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3)
*
* talloc_set_name_const(ptr, ptr)
*/
char
*
talloc_append_string
(
char
*
orig
,
const
char
*
append
);
char
*
WARN_UNUSED_RESULT
talloc_append_string
(
char
*
orig
,
const
char
*
append
);
/**
* talloc_asprintf_append - sprintf onto the end of a talloc buffer.
...
...
@@ -586,7 +586,8 @@ char *talloc_append_string(char *orig, const char *append);
* equivalent to:
* talloc_set_name_const(ptr, ptr)
*/
char
*
talloc_asprintf_append
(
char
*
s
,
const
char
*
fmt
,
...)
PRINTF_ATTRIBUTE
(
2
,
3
);
char
*
WARN_UNUSED_RESULT
talloc_asprintf_append
(
char
*
s
,
const
char
*
fmt
,
...)
PRINTF_ATTRIBUTE
(
2
,
3
);
/**
* talloc_vasprintf - vsprintf into a talloc buffer.
...
...
@@ -613,7 +614,8 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIB
* The talloc_vasprintf_append() function is equivalent to
* talloc_asprintf_append(), except it takes a va_list.
*/
char
*
talloc_vasprintf_append
(
char
*
s
,
const
char
*
fmt
,
va_list
ap
)
PRINTF_ATTRIBUTE
(
2
,
0
);
char
*
WARN_UNUSED_RESULT
talloc_vasprintf_append
(
char
*
s
,
const
char
*
fmt
,
va_list
ap
)
PRINTF_ATTRIBUTE
(
2
,
0
);
/**
* talloc_set_type - force the name of a pointer to a particular type
...
...
@@ -962,7 +964,7 @@ void _talloc_set_destructor(const void *ptr, int (*destructor)(void *));
size_t
talloc_reference_count
(
const
void
*
ptr
);
void
*
_talloc_reference
(
const
void
*
context
,
const
void
*
ptr
);
void
*
_talloc_realloc
(
const
void
*
context
,
void
*
ptr
,
size_t
size
,
const
char
*
name
);
void
*
WARN_UNUSED_RESULT
_talloc_realloc
(
const
void
*
context
,
void
*
ptr
,
size_t
size
,
const
char
*
name
);
void
*
talloc_parent
(
const
void
*
ptr
);
const
char
*
talloc_parent_name
(
const
void
*
ptr
);
void
*
_talloc_steal
(
const
void
*
new_ctx
,
const
void
*
ptr
);
...
...
@@ -971,7 +973,7 @@ void *_talloc_zero(const void *ctx, size_t size, const char *name);
void
*
_talloc_memdup
(
const
void
*
t
,
const
void
*
p
,
size_t
size
,
const
char
*
name
);
void
*
_talloc_array
(
const
void
*
ctx
,
size_t
el_size
,
unsigned
count
,
const
char
*
name
);
void
*
_talloc_zero_array
(
const
void
*
ctx
,
size_t
el_size
,
unsigned
count
,
const
char
*
name
);
void
*
_talloc_realloc_array
(
const
void
*
ctx
,
void
*
ptr
,
size_t
el_size
,
unsigned
count
,
const
char
*
name
);
void
*
WARN_UNUSED_RESULT
_talloc_realloc_array
(
const
void
*
ctx
,
void
*
ptr
,
size_t
el_size
,
unsigned
count
,
const
char
*
name
);
void
*
talloc_realloc_fn
(
const
void
*
context
,
void
*
ptr
,
size_t
size
);
void
talloc_show_parents
(
const
void
*
context
,
FILE
*
file
);
int
talloc_is_parent
(
const
void
*
context
,
const
void
*
ptr
);
...
...
ccan/talloc/test/run.c
View file @
d40331c7
...
...
@@ -438,14 +438,14 @@ static bool test_realloc(const struct torture_context *ctx)
"failed: talloc_realloc() on a referenced pointer should fail
\n
"
);
CHECK_BLOCKS
(
"realloc"
,
p1
,
4
);
talloc_realloc_size
(
NULL
,
p2
,
0
);
talloc_realloc_size
(
NULL
,
p2
,
0
);
ok1
(
talloc_realloc_size
(
NULL
,
p2
,
0
)
==
NULL
);
ok1
(
talloc_realloc_size
(
NULL
,
p2
,
0
)
==
NULL
);
CHECK_BLOCKS
(
"realloc"
,
p1
,
3
);
torture_assert
(
"realloc"
,
talloc_realloc_size
(
NULL
,
p1
,
0x7fffffff
)
==
NULL
,
"failed: oversize talloc should fail
\n
"
);
talloc_realloc_size
(
NULL
,
p1
,
0
);
p1
=
talloc_realloc_size
(
NULL
,
p1
,
0
);
CHECK_BLOCKS
(
"realloc"
,
root
,
1
);
CHECK_SIZE
(
"realloc"
,
root
,
0
);
...
...
@@ -948,7 +948,7 @@ int main(void)
{
struct
torture_context
*
ctx
;
plan_tests
(
28
4
);
plan_tests
(
28
8
);
ctx
=
talloc_add_external
(
NULL
,
normal_realloc
,
test_lock
,
test_unlock
);
torture_local_talloc
(
NULL
);
...
...
config.h
View file @
d40331c7
/* Simple config.h for recent gcc. */
#define HAVE_ALIGNOF 1
#define HAVE_ATTRIBUTE_CONST 1
#define HAVE_ATTRIBUTE_COLD 1
#define HAVE_ATTRIBUTE_CONST 1
#define HAVE_ATTRIBUTE_MAY_ALIAS 1
#define HAVE_ATTRIBUTE_PRINTF 1
#define HAVE_ATTRIBUTE_USED 1
#define HAVE_ATTRIBUTE_UNUSED 1
#define HAVE_ATTRIBUTE_USED 1
#define HAVE_BIG_ENDIAN 0
#define HAVE_BSWAP_64 1
#define HAVE_BUILTIN_CHOOSE_EXPR 1
#define HAVE_BUILTIN_CLZ 1
#define HAVE_BUILTIN_CLZL 1
#define HAVE_BUILTIN_CLZLL 1
#define HAVE_BUILTIN_CONSTANT_P 1
#define HAVE_BUILTIN_EXPECT 1
#define HAVE_BUILTIN_FFSL 1
#define HAVE_BUILTIN_POPCOUNTL 1
#define HAVE_BUILTIN_TYPES_COMPATIBLE_P 1
#define HAVE_BYTESWAP_H 1
#define HAVE_GETPAGESIZE 1
#define HAVE_LITTLE_ENDIAN 1
#define HAVE_MMAP 1
...
...
@@ -18,10 +25,4 @@
#define HAVE_STATEMENT_EXPR 1
#define HAVE_TYPEOF 1
#define HAVE_UTIME 1
#define HAVE_BUILTIN_CLZ 1
#define HAVE_BUILTIN_CLZL 1
#define HAVE_BUILTIN_CLZLL 1
#define HAVE_BUILTIN_FFSL 1
#define HAVE_BUILTIN_POPCOUNTL 1
#define HAVE_BYTESWAP_H 1
#define HAVE_BSWAP_64 1
#define HAVE_WARN_UNUSED_RESULT 1
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