Message ID | tencent_DB960C1E4E3B7A2A549B3D95DF223BDAEC06@qq.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | tests/nsm_client: Fix nsm_client compile warnings | expand |
On 16 Jul 2024, at 22:26, 597607025@qq.com wrote: > From: Zhang Yaqi <zhangyaqi@kylinos.cn> > > when compiling after make > cd tests/nsm_client > make nsm_client > then it shows: > > nsm_client.c: In function hex2bin: > nsm_client.c:104:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] > for (i = 0; *src && i < dstlen; i++) { > ^ > nsm_client.c: In function bin2hex: > nsm_client.c:122:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] > for (i = 0; i < srclen; i++) > > Signed-off-by: Zhang Yaqi <zhangyaqi@kylinos.cn> Why not just to make the types match, rather than cast? Ben
diff --git a/tests/nsm_client/nsm_client.c b/tests/nsm_client/nsm_client.c index 8dc05917..67b593fa 100644 --- a/tests/nsm_client/nsm_client.c +++ b/tests/nsm_client/nsm_client.c @@ -101,7 +101,7 @@ hex2bin(char *dst, size_t dstlen, char *src) int i; unsigned int tmp; - for (i = 0; *src && i < dstlen; i++) { + for (i = 0; *src && (size_t)i < dstlen; i++) { if (sscanf(src, "%2x", &tmp) != 1) return 0; dst[i] = tmp; @@ -119,7 +119,7 @@ bin2hex(char *dst, char *src, size_t srclen) { int i; - for (i = 0; i < srclen; i++) + for (i = 0; (size_t)i < srclen; i++) dst += sprintf(dst, "%02x", 0xff & src[i]); }