Skip to contentSkip to conversation

ell: cast printf call to double

PATCH In review Rosen Penev 2 participants 4 messages Jul 21, 2020 – Jul 22, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ell: cast printf call to double

%f confusingly enough takes a bool, not a float.

---
 ell/settings.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ell/settings.c +1 -1
index 945dff7..dac45c9 100644
@@ -1320,7 +1320,7 @@ LIB_EXPORT bool l_settings_set_float(struct l_settings *settings,
 {
 	L_AUTO_FREE_VAR(char *, buf);
 
-	buf = l_strdup_printf("%f", in);
+	buf = l_strdup_printf("%f", (double)in);
 
 	return l_settings_set_value(settings, group_name, key, buf);
 }
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/3 ell: match declaration names

Found with clang-tidy's readability-inconsistent-declaration-parameter-name

---
 ell/cert-private.h | 2 +-
 ell/dbus-private.h | 2 +-
 ell/ecc-private.h  | 4 ++--
 ell/log.h          | 2 +-
 ell/rtnl.h         | 2 +-
 ell/utf8.h         | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)
ell/cert-private.h +1 -1
index ba9a513..929f88d 100644
@@ -23,7 +23,7 @@
 struct asn1_oid;
 
 struct l_certchain *certchain_new_from_leaf(struct l_cert *leaf);
-void certchain_link_issuer(struct l_certchain *chain, struct l_cert *issuer);
+void certchain_link_issuer(struct l_certchain *chain, struct l_cert *ca);
 
 const uint8_t *cert_get_extension(struct l_cert *cert,
 					const struct asn1_oid *ext_id,
ell/dbus-private.h +1 -1
index d34a298..66a585e 100644
@@ -179,7 +179,7 @@ void _dbus_property_introspection(struct _dbus_property *info,
 void _dbus_interface_introspection(struct l_dbus_interface *interface,
 						struct l_string *buf);
 
-struct l_dbus_interface *_dbus_interface_new(const char *interface);
+struct l_dbus_interface *_dbus_interface_new(const char *name);
 void _dbus_interface_free(struct l_dbus_interface *interface);
 
 struct _dbus_method *_dbus_interface_find_method(struct l_dbus_interface *i,
ell/ecc-private.h +2 -2
index 0e85d98..70d9607 100644
@@ -59,10 +59,10 @@ void _vli_mod_inv(uint64_t *result, const uint64_t *input, const uint64_t *mod,
 			unsigned int ndigits);
 
 void _vli_mod_sub(uint64_t *result, const uint64_t *left, const uint64_t *right,
-		const uint64_t *curve_prime, unsigned int ndigits);
+		const uint64_t *mod, unsigned int ndigits);
 
 void _vli_mod_add(uint64_t *result, const uint64_t *left, const uint64_t *right,
-			const uint64_t *curve_prime, unsigned int ndigits);
+			const uint64_t *mod, unsigned int ndigits);
 
 void _vli_rshift1(uint64_t *vli, unsigned int ndigits);
 
ell/log.h +1 -1
index 19bf10b..924523b 100644
@@ -74,7 +74,7 @@ struct l_debug_desc {
 
 void l_debug_enable_full(const char *pattern,
 				struct l_debug_desc *start,
-				struct l_debug_desc *stop);
+				struct l_debug_desc *end);
 void l_debug_add_section(struct l_debug_desc *start,
 					struct l_debug_desc *end);
 
ell/rtnl.h +1 -1
index 60b8db4..a0c06ed 100644
@@ -83,7 +83,7 @@ uint32_t l_rtnl_route4_add_gateway(struct l_netlink *rtnl, int ifindex,
 					void *user_data,
 					l_netlink_destroy_func_t destroy);
 
-void l_rtnl_ifaddr6_extract(const struct ifaddrmsg *ifa, int bytes,
+void l_rtnl_ifaddr6_extract(const struct ifaddrmsg *ifa, int len,
 								char **ip);
 uint32_t l_rtnl_ifaddr6_dump(struct l_netlink *rtnl,
 				l_netlink_command_func_t cb,
ell/utf8.h +1 -1
index c92da60..d1b1811 100644
@@ -102,7 +102,7 @@ static inline __attribute__ ((always_inline)) bool l_ascii_isascii(int c)
 }
 
 bool l_utf8_validate(const char *src, size_t len, const char **end);
-size_t l_utf8_strlen(const char *src);
+size_t l_utf8_strlen(const char *str);
 
 int l_utf8_get_codepoint(const char *str, size_t len, wchar_t *cp);
 size_t l_utf8_from_wchar(wchar_t c, char *out_buf);
Signature · 1 line
2.26.2
#2 lore raw

PATCH 3/3 ell: don't use else after return

In reply to Rosen Penev

Found with clang-tidy's readability-else-after-return

---
 ell/ecc-external.c   |  2 +-
 ell/ecc.c            |  5 ++---
 ell/gvariant-util.c  |  8 +++-----
 ell/key.c            | 15 +++++++--------
 ell/queue.c          |  6 +++---
 ell/tls-extensions.c |  3 ++-
 ell/tls.c            |  3 +--
 tools/gpio.c         | 11 +++++------
 8 files changed, 24 insertions(+), 29 deletions(-)
ell/ecc-external.c +1 -1
index 1c118c2..13b55e6 100644
@@ -85,7 +85,7 @@ int _vli_cmp(const uint64_t *left, const uint64_t *right, unsigned int ndigits)
 	for (i = ndigits - 1; i >= 0; i--) {
 		if (left[i] > right[i])
 			return 1;
-		else if (left[i] < right[i])
+		if (left[i] < right[i])
 			return -1;
 	}
 
ell/ecc.c +2 -3
index d0c7393..250f7e8 100644
@@ -442,10 +442,9 @@ int _vli_legendre(uint64_t *val, const uint64_t *p, unsigned int ndigits)
 
 	if (_vli_cmp(tmp, _1, ndigits) == 0)
 		return 1;
-	else if (_vli_cmp(tmp, _0, ndigits) == 0)
+	if (_vli_cmp(tmp, _0, ndigits) == 0)
 		return 0;
-	else
-		return -1;
+	return -1;
 }
 
 static bool vli_is_zero_or_one(const uint64_t *vli, unsigned int ndigits)
ell/gvariant-util.c +3 -5
index cf0161a..d6ebb64 100644
@@ -307,8 +307,7 @@ static inline size_t offset_length(size_t size, size_t n_offsets)
 		return 2;
 	if (size + n_offsets * 4 <= 0xffffffff)
 		return 4;
-	else
-		return 8;
+	return 8;
 }
 
 static inline size_t read_word_le(const void *p, size_t sz) {
@@ -325,10 +324,9 @@ static inline size_t read_word_le(const void *p, size_t sz) {
 
 	if (sz == 2)
 		return le16toh(x.u16);
-	else if (sz == 4)
+	if (sz == 4)
 		return le32toh(x.u32);
-	else
-		return le64toh(x.u64);
+	return le64toh(x.u64);
 }
 
 static inline void write_word_le(void *p, size_t value, size_t sz) {
ell/key.c +7 -8
index 2e4f3e6..62bd72a 100644
@@ -500,9 +500,8 @@ static bool compute_common(struct l_key *base, struct l_key *private,
 	if (result_len > 0) {
 		*len = result_len;
 		return usable_payload;
-	} else {
-		return false;
 	}
+	return false;
 }
 
 LIB_EXPORT bool l_key_compute_dh_public(struct l_key *generator,
@@ -532,13 +531,13 @@ static int be_bignum_compare(const uint8_t *a, size_t a_len,
 				return 1;
 
 		return memcmp(a + i, b, b_len);
-	} else {
-		for (i = 0; i < b_len - a_len; i++)
-			if (b[i])
-				return -1;
-
-		return memcmp(a, b + i, a_len);
 	}
+
+	for (i = 0; i < b_len - a_len; i++)
+		if (b[i])
+			return -1;
+
+	return memcmp(a, b + i, a_len);
 }
 
 /*
ell/queue.c +3 -3
index 0f6ed3e..86c52ed 100644
@@ -533,10 +533,10 @@ LIB_EXPORT void *l_queue_remove_if(struct l_queue *queue,
 			queue->entries--;
 
 			return data;
-		} else {
-			prev = entry;
-			entry = entry->next;
 		}
+
+		prev = entry;
+		entry = entry->next;
 	}
 
 	return NULL;
ell/tls-extensions.c +2 -1
index 2e2d9da..6154df0 100644
@@ -742,7 +742,8 @@ ssize_t tls_parse_signature_algorithms(struct l_tls *tls,
 				 tls->pending.cipher_suite->signature->id !=
 				 sig_alg_id))
 			continue;
-		else if (!tls->pending.cipher_suite &&
+
+		if (!tls->pending.cipher_suite &&
 				!memchr(sig_alg_ids, sig_alg_id, sig_alg_cnt))
 			continue;
 
ell/tls.c +1 -2
index 6b47bea..5bf6573 100644
@@ -134,8 +134,7 @@ static bool tls_prf_get_bytes(struct l_tls *tls,
 		return tls12_prf(tls->prf_hmac->l_id,
 					secret, secret_len, label,
 					seed, seed_len, buf, len);
-	else
-		return tls10_prf(secret, secret_len, label, seed, seed_len,
+	return tls10_prf(secret, secret_len, label, seed, seed_len,
 					buf, len);
 }
 
tools/gpio.c +5 -6
index 0fdb31e..0db596e 100644
@@ -252,14 +252,13 @@ int main(int argc, char **argv)
 
 	if (strcmp(cmd, "get") == 0)
 		return get(argc, argv);
-	else if (strcmp(cmd, "set") == 0)
+	if (strcmp(cmd, "set") == 0)
 		return set(argc, argv);
-	else if (strcmp(cmd, "find") == 0)
+	if (strcmp(cmd, "find") == 0)
 		return find(argc, argv);
-	else if (strcmp(cmd, "chip") == 0)
+	if (strcmp(cmd, "chip") == 0)
 		return chip(argc, argv);
-	else if (strcmp(cmd, "line") == 0)
+	if (strcmp(cmd, "line") == 0)
 		return line(argc, argv);
-	else
-		return print_usage();
+	return print_usage();
 }
Signature · 1 line
2.26.2
#3 lore raw
In reply to Rosen Penev
Quoted 1 line · On Tue, 21 Jul 2020 15:39:57 -0700 Rosen Penev <[email protected]> wrote:

%f confusingly enough takes a bool, not a float.

takes a _double_, most likely not a bool :-)

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com