cifs-utils: fix up some compiler warnings in asn1.c
Subsystems (2)
PATCH 1/1 cifs-utils: fix up some compiler warnings in asn1.c
These have been around for quite some time.
gcc -DHAVE_CONFIG_H -I. -Wall -Wextra -g -O2 -MT asn1.o -MD -MP -MF
.deps/asn1.Tpo -c -o asn1.o asn1.casn1.c: In function ‘asn1_write’:
asn1.c:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]asn1.c: In function ‘asn1_peek’:
asn1.c:411:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]asn1.c: In function ‘asn1_tag_remaining’:
asn1.c:541:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]asn1.c: In function ‘_ber_read_OID_String_impl’:
asn1.c:570:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
Almost all of these are due to the fact that asn1_data->ofs is a signed value, and ->length is unsigned. In most cases, I've fixed it by casting ofs to an unsigned value, but in one case, I cast length to a signed value since it looked possible for the result to go negative.
Hopefully the values here will always be small enough that this is never a real problem.
This should clear the way to add -Werror to the cflags in the near future.
--- asn1.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
asn1.c +6 -5
@@ -41,8 +41,9 @@ void asn1_free(struct asn1_data *data)/* write to the ASN1 buffer, advancing the buffer pointer */ bool asn1_write (struct asn1_data *data,const void *p,int len) { -if (data->has_error)return false; -if (data->length < data->ofs+len) { +if (data->has_error) +return false; +if (data->length < (size_t )data->ofs + len) {uint8_t *newp; newp =talloc_realloc (data, data->data, uint8_t, data->ofs+len);if (!newp) {
@@ -408,7 +409,7 @@ bool asn1_peek(struct asn1_data *data, void *p, int len)if (len <0 || data->ofs + len < data->ofs || data->ofs + len < len)return false; -if (data->ofs + len > data->length) { +if ((size_t )data->ofs + len > data->length) {/* we need to mark the buffer as consumed, so the caller knows this was an out of data error, and not a decode error */ data->ofs = data->length;
@@ -538,7 +539,7 @@ int asn1_tag_remaining(struct asn1_data *data)return -1 ; } remaining = data->nesting->taglen - (data->ofs - data->nesting->start); -if (remaining > (data->length - data->ofs)) { +if (remaining > (ssize_t )data->length - data->ofs) { data->has_error = true;return -1 ; }
@@ -553,7 +554,7 @@ int asn1_tag_remaining(struct asn1_data *data)static bool _ber_read_OID_String_impl (TALLOC_CTX *mem_ctx,DATA_BLOB blob,const char **OID ,size_t *bytes_eaten) { -int i; +unsigned int i;uint8_t *b;unsigned int v;char *tmp_oid =NULL ;
Signature · 1 line
1.7.7.6
A message that is not in the archive (sent off-list or not yet received): 1334490685-14366-1-git-send-email-jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org
Quoted 69 lines · On Sun, 15 Apr 2012 07:51:25 -0400 Jeff Layton…
These have been around for quite some time.
gcc -DHAVE_CONFIG_H -I. -Wall -Wextra -g -O2 -MT asn1.o -MD -MP -MF
.deps/asn1.Tpo -c -o asn1.oasn1.casn1.c: In function ‘asn1_write’:
asn1.c:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]asn1.c: In function ‘asn1_peek’:
asn1.c:411:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]asn1.c: In function ‘asn1_tag_remaining’:
asn1.c:541:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]asn1.c: In function ‘_ber_read_OID_String_impl’:
asn1.c:570:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]Almost all of these are due to the fact that
asn1_data->ofsis a signed value, and ->length is unsigned. In most cases, I've fixed it by casting ofs to an unsigned value, but in one case, I cast length to a signed value since it looked possible for the result to go negative.Hopefully the values here will always be small enough that this is never a real problem.
This should clear the way to add -Werror to the cflags in the near future.
Signed-off-by Jeff Layton <[email protected]>--- asn1.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)asn1.c +5
-4@@ -41,8 +41,9 @@ void asn1_free(struct asn1_data *data)/* write to the ASN1 buffer, advancing the buffer pointer */ bool asn1_write (struct asn1_data *data,const void *p,int len) { -if (data->has_error)return false; -if (data->length < data->ofs+len) { +if (data->has_error) +return false; +if (data->length < (size_t )data->ofs + len) {uint8_t *newp; newp =talloc_realloc (data, data->data, uint8_t, data->ofs+len);if (!newp) {@@ -408,7 +409,7 @@ bool asn1_peek(struct asn1_data *data, void *p, int len)if (len <0 || data->ofs + len < data->ofs || data->ofs + len < len)return false; -if (data->ofs + len > data->length) { +if ((size_t )data->ofs + len > data->length) {/* we need to mark the buffer as consumed, so the caller knows this was an out of data error, and not a decode error */ data->ofs = data->length;@@ -538,7 +539,7 @@ int asn1_tag_remaining(struct asn1_data *data)return -1 ; } remaining = data->nesting->taglen - (data->ofs - data->nesting->start); -if (remaining > (data->length - data->ofs)) { +if (remaining > (ssize_t )data->length - data->ofs) { data->has_error = true;return -1 ; }
asn1.c int asn1_tag_remaining(struct asn1_data *data) · line 560
Quoted 8 lines
asn1.c +1
-1@@ -553,7 +554,7 @@ int asn1_tag_remaining(struct asn1_data *data)static bool _ber_read_OID_String_impl (TALLOC_CTX *mem_ctx,DATA_BLOB blob,const char **OID ,size_t *bytes_eaten) { -int i; +unsigned int i;uint8_t *b;unsigned int v;char *tmp_oid =NULL ;
Merged...
Signature · 1 line
Jeff Layton <[email protected]>