summaryrefslogtreecommitdiffstats
path: root/lib/utils.c
diff options
context:
space:
mode:
authorКоренберг Марк <mark@ideco.ru>2012-06-08 14:15:06 (GMT)
committerThomas Graf <tgraf@redhat.com>2012-06-13 11:30:26 (GMT)
commit2bdcde7e8e8bb78b165f093f1a708134f417e557 (patch)
tree52d56b1b1d1f75373a33c27988ded96e6a62e36e /lib/utils.c
parent4f933648622fff2b7fd6ec6c71724da4992c2544 (diff)
downloadlibnl-2bdcde7e8e8bb78b165f093f1a708134f417e557.zip
libnl-2bdcde7e8e8bb78b165f093f1a708134f417e557.tar.gz
libnl-2bdcde7e8e8bb78b165f093f1a708134f417e557.tar.bz2
Fix types-related warnings based on clang diagnostics
1. Fix some places where unsigned value compared < 0 2. Fix obsolete %Z specifier to more portable %z 3. Some erroneous types substitution 4. nl_msec2str() - 64-bit msec is now properly used, Only safe changes. I mean int <--> uint32_t and signed/unsigned fixes. Some functinos require size_t argument instead of int, but changes of signatures of that functions is terrible thing. Also, I do not pretend for a full list of fixes. Just to shut up clang -Wall -Wextra One more thing. ifindex. I don't change that because changes will be too big for simple fix.
Diffstat (limited to 'lib/utils.c')
-rw-r--r--lib/utils.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/utils.c b/lib/utils.c
index efb2cf4..467fd7f 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -305,7 +305,7 @@ static const struct {
*/
char *nl_size2str(const size_t size, char *buf, const size_t len)
{
- int i;
+ size_t i;
for (i = 0; i < ARRAY_SIZE(size_units); i++) {
if (size >= size_units[i].limit) {
@@ -515,10 +515,12 @@ int nl_str2msec(const char *str, uint64_t *result)
*/
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
{
- int i, split[5];
- char *units[] = {"d", "h", "m", "s", "msec"};
+ uint64_t split[5];
+ size_t i;
+ static const char *units[5] = {"d", "h", "m", "s", "msec"};
+ char * const buf_orig = buf;
-#define _SPLIT(idx, unit) if ((split[idx] = msec / unit) > 0) msec %= unit
+#define _SPLIT(idx, unit) if ((split[idx] = msec / unit)) msec %= unit
_SPLIT(0, 86400000); /* days */
_SPLIT(1, 3600000); /* hours */
_SPLIT(2, 60000); /* minutes */
@@ -526,18 +528,17 @@ char * nl_msec2str(uint64_t msec, char *buf, size_t len)
#undef _SPLIT
split[4] = msec;
- memset(buf, 0, len);
-
- for (i = 0; i < ARRAY_SIZE(split); i++) {
- if (split[i] > 0) {
- char t[64];
- snprintf(t, sizeof(t), "%s%d%s",
- strlen(buf) ? " " : "", split[i], units[i]);
- strncat(buf, t, len - strlen(buf) - 1);
- }
+ for (i = 0; i < ARRAY_SIZE(split) && len; i++) {
+ int l;
+ if (split[i] == 0)
+ continue;
+ l = snprintf(buf, len, "%s%" PRIu64 "%s",
+ (buf==buf_orig) ? "" : " ", split[i], units[i]);
+ buf += l;
+ len -= l;
}
- return buf;
+ return buf_orig;
}
/** @} */
@@ -929,7 +930,7 @@ void __trans_list_clear(struct nl_list_head *head)
char *__type2str(int type, char *buf, size_t len,
const struct trans_tbl *tbl, size_t tbl_len)
{
- int i;
+ size_t i;
for (i = 0; i < tbl_len; i++) {
if (tbl[i].i == type) {
snprintf(buf, len, "%s", tbl[i].a);
@@ -960,7 +961,7 @@ char *__list_type2str(int type, char *buf, size_t len,
char *__flags2str(int flags, char *buf, size_t len,
const struct trans_tbl *tbl, size_t tbl_len)
{
- int i;
+ size_t i;
int tmp = flags;
memset(buf, 0, len);
@@ -981,7 +982,7 @@ int __str2type(const char *buf, const struct trans_tbl *tbl, size_t tbl_len)
{
unsigned long l;
char *end;
- int i;
+ size_t i;
if (*buf == '\0')
return -NLE_INVAL;
@@ -1020,7 +1021,9 @@ int __list_str2type(const char *buf, struct nl_list_head *head)
int __str2flags(const char *buf, const struct trans_tbl *tbl, size_t tbl_len)
{
- int i, flags = 0, len;
+ int flags = 0;
+ size_t i;
+ size_t len; /* ptrdiff_t ? */
char *p = (char *) buf, *t;
for (;;) {