Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
7cba1a27
Unverified
Commit
7cba1a27
authored
Aug 29, 2018
by
Christian Brauner
Committed by
GitHub
Aug 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2577 from Blub/inttype-lengths
tree-wide: use sizeof on static arrays
parents
f288e10a
81a3bb64
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
25 additions
and
25 deletions
+25
-25
caps.c
src/lxc/caps.c
+1
-1
cgfsng.c
src/lxc/cgroups/cgfsng.c
+2
-2
log.c
src/lxc/log.c
+2
-2
lxccontainer.c
src/lxc/lxccontainer.c
+2
-2
monitor.c
src/lxc/monitor.c
+2
-2
lxc_monitor.c
src/lxc/tools/lxc_monitor.c
+2
-2
utils.c
src/lxc/utils.c
+2
-2
lxc-test-utils.c
src/tests/lxc-test-utils.c
+12
-12
No files found.
src/lxc/caps.c
View file @
7cba1a27
...
@@ -299,7 +299,7 @@ static long int _real_caps_last_cap(void)
...
@@ -299,7 +299,7 @@ static long int _real_caps_last_cap(void)
char
buf
[
INTTYPE_TO_STRLEN
(
int
)];
char
buf
[
INTTYPE_TO_STRLEN
(
int
)];
again:
again:
n
=
read
(
fd
,
buf
,
INTTYPE_TO_STRLEN
(
int
));
n
=
read
(
fd
,
buf
,
sizeof
(
buf
));
if
(
n
<
0
&&
errno
==
EINTR
)
{
if
(
n
<
0
&&
errno
==
EINTR
)
{
goto
again
;
goto
again
;
}
else
if
(
n
>=
0
)
{
}
else
if
(
n
>=
0
)
{
...
...
src/lxc/cgroups/cgfsng.c
View file @
7cba1a27
...
@@ -321,8 +321,8 @@ static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
...
@@ -321,8 +321,8 @@ static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
if
(
!
is_set
(
i
,
bitarr
))
if
(
!
is_set
(
i
,
bitarr
))
continue
;
continue
;
ret
=
snprintf
(
numstr
,
INTTYPE_TO_STRLEN
(
size_t
),
"%zu"
,
i
);
ret
=
snprintf
(
numstr
,
sizeof
(
numstr
),
"%zu"
,
i
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
INTTYPE_TO_STRLEN
(
size_t
))
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
numstr
))
{
lxc_free_array
((
void
**
)
cpulist
,
free
);
lxc_free_array
((
void
**
)
cpulist
,
free
);
return
NULL
;
return
NULL
;
}
}
...
...
src/lxc/log.c
View file @
7cba1a27
...
@@ -247,8 +247,8 @@ static int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespe
...
@@ -247,8 +247,8 @@ static int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespe
seconds
=
(
time
->
tv_sec
-
d_in_s
-
h_in_s
-
(
minutes
*
60
));
seconds
=
(
time
->
tv_sec
-
d_in_s
-
h_in_s
-
(
minutes
*
60
));
/* Make string from nanoseconds. */
/* Make string from nanoseconds. */
ret
=
snprintf
(
nanosec
,
INTTYPE_TO_STRLEN
(
int64_t
),
"%"
PRId64
,
(
int64_t
)
time
->
tv_nsec
);
ret
=
snprintf
(
nanosec
,
sizeof
(
nanosec
),
"%"
PRId64
,
(
int64_t
)
time
->
tv_nsec
);
if
(
ret
<
0
||
ret
>=
INTTYPE_TO_STRLEN
(
int64_t
))
if
(
ret
<
0
||
ret
>=
sizeof
(
nanosec
))
return
-
1
;
return
-
1
;
/* Create final timestamp for the log and shorten nanoseconds to 3
/* Create final timestamp for the log and shorten nanoseconds to 3
...
...
src/lxc/lxccontainer.c
View file @
7cba1a27
...
@@ -1039,8 +1039,8 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
...
@@ -1039,8 +1039,8 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
int
ret
,
w
;
int
ret
,
w
;
char
pidstr
[
INTTYPE_TO_STRLEN
(
int
)];
char
pidstr
[
INTTYPE_TO_STRLEN
(
int
)];
w
=
snprintf
(
pidstr
,
INTTYPE_TO_STRLEN
(
int
),
"%d"
,
(
int
)
lxc_raw_getpid
());
w
=
snprintf
(
pidstr
,
sizeof
(
pidstr
),
"%d"
,
(
int
)
lxc_raw_getpid
());
if
(
w
<
0
||
(
size_t
)
w
>=
INTTYPE_TO_STRLEN
(
int
))
{
if
(
w
<
0
||
(
size_t
)
w
>=
sizeof
(
pidstr
))
{
free_init_cmd
(
init_cmd
);
free_init_cmd
(
init_cmd
);
lxc_free_handler
(
handler
);
lxc_free_handler
(
handler
);
...
...
src/lxc/monitor.c
View file @
7cba1a27
...
@@ -371,8 +371,8 @@ int lxc_monitord_spawn(const char *lxcpath)
...
@@ -371,8 +371,8 @@ int lxc_monitord_spawn(const char *lxcpath)
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
ret
=
snprintf
(
pipefd_str
,
INTTYPE_TO_STRLEN
(
int
),
"%d"
,
pipefd
[
1
]);
ret
=
snprintf
(
pipefd_str
,
sizeof
(
pipefd_str
),
"%d"
,
pipefd
[
1
]);
if
(
ret
<
0
||
ret
>=
INTTYPE_TO_STRLEN
(
int
))
{
if
(
ret
<
0
||
ret
>=
sizeof
(
pipefd_str
))
{
ERROR
(
"Failed to create pid argument to pass to monitord."
);
ERROR
(
"Failed to create pid argument to pass to monitord."
);
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
...
...
src/lxc/tools/lxc_monitor.c
View file @
7cba1a27
...
@@ -224,8 +224,8 @@ static int lxc_tool_monitord_spawn(const char *lxcpath)
...
@@ -224,8 +224,8 @@ static int lxc_tool_monitord_spawn(const char *lxcpath)
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
ret
=
snprintf
(
pipefd_str
,
INTTYPE_TO_STRLEN
(
int
),
"%d"
,
pipefd
[
1
]);
ret
=
snprintf
(
pipefd_str
,
sizeof
(
pipefd_str
),
"%d"
,
pipefd
[
1
]);
if
(
ret
<
0
||
ret
>=
INTTYPE_TO_STRLEN
(
int
))
{
if
(
ret
<
0
||
ret
>=
sizeof
(
pipefd_str
))
{
ERROR
(
"Failed to create pid argument to pass to monitord"
);
ERROR
(
"Failed to create pid argument to pass to monitord"
);
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
...
...
src/lxc/utils.c
View file @
7cba1a27
...
@@ -1165,7 +1165,7 @@ int lxc_mount_proc_if_needed(const char *rootfs)
...
@@ -1165,7 +1165,7 @@ int lxc_mount_proc_if_needed(const char *rootfs)
return
-
1
;
return
-
1
;
}
}
linklen
=
readlink
(
path
,
link
,
INTTYPE_TO_STRLEN
(
pid_t
));
linklen
=
readlink
(
path
,
link
,
sizeof
(
link
));
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/proc"
,
rootfs
);
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/proc"
,
rootfs
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
{
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
{
...
@@ -1179,7 +1179,7 @@ int lxc_mount_proc_if_needed(const char *rootfs)
...
@@ -1179,7 +1179,7 @@ int lxc_mount_proc_if_needed(const char *rootfs)
return
-
1
;
return
-
1
;
goto
domount
;
goto
domount
;
}
else
if
(
linklen
>=
INTTYPE_TO_STRLEN
(
pid_t
))
{
}
else
if
(
linklen
>=
sizeof
(
link
))
{
link
[
linklen
-
1
]
=
'\0'
;
link
[
linklen
-
1
]
=
'\0'
;
ERROR
(
"readlink returned truncated content:
\"
%s
\"
"
,
link
);
ERROR
(
"readlink returned truncated content:
\"
%s
\"
"
,
link
);
return
-
1
;
return
-
1
;
...
...
src/tests/lxc-test-utils.c
View file @
7cba1a27
...
@@ -252,14 +252,14 @@ void test_lxc_safe_uint(void)
...
@@ -252,14 +252,14 @@ void test_lxc_safe_uint(void)
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
" -123"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
" -123"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
"-123"
,
&
n
)));
lxc_test_assert_abort
((
-
EINVAL
==
lxc_safe_uint
(
"-123"
,
&
n
)));
ret
=
snprintf
(
numstr
,
INTTYPE_TO_STRLEN
(
uint64_t
),
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
);
ret
=
snprintf
(
numstr
,
sizeof
(
numstr
),
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
);
if
(
ret
<
0
||
ret
>=
INTTYPE_TO_STRLEN
(
uint64_t
))
if
(
ret
<
0
||
ret
>=
sizeof
(
numstr
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
numstr
,
&
n
))
&&
n
==
UINT_MAX
);
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
numstr
,
&
n
))
&&
n
==
UINT_MAX
);
ret
=
snprintf
(
numstr
,
INTTYPE_TO_STRLEN
(
uint64_t
),
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
+
1
);
ret
=
snprintf
(
numstr
,
sizeof
(
numstr
),
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
+
1
);
if
(
ret
<
0
||
ret
>=
INTTYPE_TO_STRLEN
(
uint64_t
))
if
(
ret
<
0
||
ret
>=
sizeof
(
numstr
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_uint
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_uint
(
numstr
,
&
n
)));
...
@@ -285,26 +285,26 @@ void test_lxc_safe_int(void)
...
@@ -285,26 +285,26 @@ void test_lxc_safe_int(void)
signed
int
n
;
signed
int
n
;
char
numstr
[
INTTYPE_TO_STRLEN
(
uint64_t
)];
char
numstr
[
INTTYPE_TO_STRLEN
(
uint64_t
)];
ret
=
snprintf
(
numstr
,
INTTYPE_TO_STRLEN
(
uint64_t
),
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
);
ret
=
snprintf
(
numstr
,
sizeof
(
numstr
),
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
);
if
(
ret
<
0
||
ret
>=
INTTYPE_TO_STRLEN
(
uint64_t
))
if
(
ret
<
0
||
ret
>=
sizeof
(
numstr
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MAX
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MAX
);
ret
=
snprintf
(
numstr
,
INTTYPE_TO_STRLEN
(
uint64_t
),
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
+
1
);
ret
=
snprintf
(
numstr
,
sizeof
(
numstr
),
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
+
1
);
if
(
ret
<
0
||
ret
>=
INTTYPE_TO_STRLEN
(
uint64_t
))
if
(
ret
<
0
||
ret
>=
sizeof
(
numstr
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
ret
=
snprintf
(
numstr
,
INTTYPE_TO_STRLEN
(
int64_t
),
"%"
PRId64
,
(
int64_t
)
INT_MIN
);
ret
=
snprintf
(
numstr
,
sizeof
(
numstr
),
"%"
PRId64
,
(
int64_t
)
INT_MIN
);
if
(
ret
<
0
||
ret
>=
INTTYPE_TO_STRLEN
(
int64_t
))
if
(
ret
<
0
||
ret
>=
sizeof
(
numstr
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MIN
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MIN
);
ret
=
snprintf
(
numstr
,
INTTYPE_TO_STRLEN
(
int64_t
),
"%"
PRId64
,
(
int64_t
)
INT_MIN
-
1
);
ret
=
snprintf
(
numstr
,
sizeof
(
numstr
),
"%"
PRId64
,
(
int64_t
)
INT_MIN
-
1
);
if
(
ret
<
0
||
ret
>=
INTTYPE_TO_STRLEN
(
int64_t
))
if
(
ret
<
0
||
ret
>=
sizeof
(
numstr
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
...
...
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