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
73c02ec4
Commit
73c02ec4
authored
Jan 07, 2017
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
str: make sure STR_MAX_CHARS gives a constant expression.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
97ac5832
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
1 deletion
+9
-1
ccan/str/str.h
ccan/str/str.h
+1
-1
ccan/str/test/compile_ok-STR_MAX_CHARS-static.c
ccan/str/test/compile_ok-STR_MAX_CHARS-static.c
+8
-0
No files found.
ccan/str/str.h
View file @
73c02ec4
...
@@ -94,7 +94,7 @@ size_t strcount(const char *haystack, const char *needle);
...
@@ -94,7 +94,7 @@ size_t strcount(const char *haystack, const char *needle);
#if HAVE_TYPEOF
#if HAVE_TYPEOF
/* Only a simple type can have 0 assigned, so test that. */
/* Only a simple type can have 0 assigned, so test that. */
#define STR_MAX_CHARS_TCHECK_(type_or_expr) \
#define STR_MAX_CHARS_TCHECK_(type_or_expr) \
(
{ typeof(type_or_expr) x = 0; (void)x; 0; }
)
(
sizeof(({ typeof(type_or_expr) x = 0; x; }))*0
)
#else
#else
#define STR_MAX_CHARS_TCHECK_(type_or_expr) 0
#define STR_MAX_CHARS_TCHECK_(type_or_expr) 0
#endif
#endif
...
...
ccan/str/test/compile_ok-STR_MAX_CHARS-static.c
0 → 100644
View file @
73c02ec4
#include <ccan/str/str.h>
int
main
(
void
)
{
static
char
str
[
STR_MAX_CHARS
(
int
)];
return
str
[
0
]
?
0
:
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