* [PATCH] cifs-utils: fix up some compiler warnings in asn1.c
@ 2012-04-15 11:51 Jeff Layton
[not found] ` <1334490685-14366-1-git-send-email-jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Jeff Layton @ 2012-04-15 11:51 UTC (permalink / raw)
To: linux-cifs-u79uwXL29TY76Z2rM5mHXA
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.c
asn1.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.
Signed-off-by: Jeff Layton <jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
---
asn1.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/asn1.c b/asn1.c
index 4103419..34475b6 100644
--- a/asn1.c
+++ b/asn1.c
@@ -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;
--
1.7.7.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] cifs-utils: fix up some compiler warnings in asn1.c
[not found] ` <1334490685-14366-1-git-send-email-jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
@ 2012-04-18 19:53 ` Jeff Layton
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Layton @ 2012-04-18 19:53 UTC (permalink / raw)
To: Jeff Layton; +Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA
On Sun, 15 Apr 2012 07:51:25 -0400
Jeff Layton <jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org> wrote:
> 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.c
> asn1.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.
>
> Signed-off-by: Jeff Layton <jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
> ---
> asn1.c | 11 ++++++-----
> 1 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/asn1.c b/asn1.c
> index 4103419..34475b6 100644
> --- a/asn1.c
> +++ b/asn1.c
> @@ -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;
Merged...
--
Jeff Layton <jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-04-18 19:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-15 11:51 [PATCH] cifs-utils: fix up some compiler warnings in asn1.c Jeff Layton
[not found] ` <1334490685-14366-1-git-send-email-jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
2012-04-18 19:53 ` Jeff Layton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.