[Qemu-devel] [PATCH v3 19/25] s390/ebcdic: Use size_t to iterate over arrays

Philippe Mathieu-Daudé posted 25 patches 6 years, 8 months ago
Maintainers: Anthony Perard <anthony.perard@citrix.com>, Li Zhijian <lizhijian@cn.fujitsu.com>, Jason Wang <jasowang@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Amit Shah <amit@kernel.org>, "Michael S. Tsirkin" <mst@redhat.com>, Paul Durrant <paul.durrant@citrix.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@de.ibm.com>, David Gibson <david@gibson.dropbear.id.au>, Zhang Chen <zhangckid@gmail.com>, Corey Minyard <minyard@acm.org>, Gerd Hoffmann <kraxel@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>, Stefan Berger <stefanb@linux.ibm.com>, Samuel Thibault <samuel.thibault@ens-lyon.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
[Qemu-devel] [PATCH v3 19/25] s390/ebcdic: Use size_t to iterate over arrays
Posted by Philippe Mathieu-Daudé 6 years, 8 months ago
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/hw/s390x/ebcdic.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/hw/s390x/ebcdic.h b/include/hw/s390x/ebcdic.h
index 69a04cab62..d89174e113 100644
--- a/include/hw/s390x/ebcdic.h
+++ b/include/hw/s390x/ebcdic.h
@@ -83,18 +83,18 @@ static const uint8_t ascii2ebcdic[] = {
     0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF
 };
 
-static inline void ebcdic_put(uint8_t *p, const char *ascii, int len)
+static inline void ebcdic_put(uint8_t *p, const char *ascii, size_t len)
 {
-    int i;
+    size_t i;
 
     for (i = 0; i < len; i++) {
         p[i] = ascii2ebcdic[(uint8_t)ascii[i]];
     }
 }
 
-static inline void ascii_put(uint8_t *p, const char *ebcdic, int len)
+static inline void ascii_put(uint8_t *p, const char *ebcdic, size_t len)
 {
-    int i;
+    size_t i;
 
     for (i = 0; i < len; i++) {
         p[i] = ebcdic2ascii[(uint8_t)ebcdic[i]];
-- 
2.20.1


Re: [Qemu-devel] [PATCH v3 19/25] s390/ebcdic: Use size_t to iterate over arrays
Posted by Cornelia Huck 6 years, 8 months ago
On Wed, 20 Feb 2019 02:02:26 +0100
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  include/hw/s390x/ebcdic.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/include/hw/s390x/ebcdic.h b/include/hw/s390x/ebcdic.h
> index 69a04cab62..d89174e113 100644
> --- a/include/hw/s390x/ebcdic.h
> +++ b/include/hw/s390x/ebcdic.h
> @@ -83,18 +83,18 @@ static const uint8_t ascii2ebcdic[] = {
>      0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF
>  };
>  
> -static inline void ebcdic_put(uint8_t *p, const char *ascii, int len)
> +static inline void ebcdic_put(uint8_t *p, const char *ascii, size_t len)
>  {
> -    int i;
> +    size_t i;
>  
>      for (i = 0; i < len; i++) {
>          p[i] = ascii2ebcdic[(uint8_t)ascii[i]];
>      }
>  }
>  
> -static inline void ascii_put(uint8_t *p, const char *ebcdic, int len)
> +static inline void ascii_put(uint8_t *p, const char *ebcdic, size_t len)
>  {
> -    int i;
> +    size_t i;
>  
>      for (i = 0; i < len; i++) {
>          p[i] = ebcdic2ascii[(uint8_t)ebcdic[i]];

Making the passed len parameter a size_t makes sense; but using a
size_t as an array iterator looks a bit unidiomatic... it's not wrong,
though.

Acked-by: Cornelia Huck <cohuck@redhat.com>

Re: [Qemu-devel] [PATCH v3 19/25] s390/ebcdic: Use size_t to iterate over arrays
Posted by Philippe Mathieu-Daudé 6 years, 8 months ago
On 2/20/19 10:40 AM, Cornelia Huck wrote:
> On Wed, 20 Feb 2019 02:02:26 +0100
> Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> 
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>  include/hw/s390x/ebcdic.h | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/hw/s390x/ebcdic.h b/include/hw/s390x/ebcdic.h
>> index 69a04cab62..d89174e113 100644
>> --- a/include/hw/s390x/ebcdic.h
>> +++ b/include/hw/s390x/ebcdic.h
>> @@ -83,18 +83,18 @@ static const uint8_t ascii2ebcdic[] = {
>>      0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF
>>  };
>>  
>> -static inline void ebcdic_put(uint8_t *p, const char *ascii, int len)
>> +static inline void ebcdic_put(uint8_t *p, const char *ascii, size_t len)
>>  {
>> -    int i;
>> +    size_t i;
>>  
>>      for (i = 0; i < len; i++) {
>>          p[i] = ascii2ebcdic[(uint8_t)ascii[i]];
>>      }
>>  }
>>  
>> -static inline void ascii_put(uint8_t *p, const char *ebcdic, int len)
>> +static inline void ascii_put(uint8_t *p, const char *ebcdic, size_t len)
>>  {
>> -    int i;
>> +    size_t i;
>>  
>>      for (i = 0; i < len; i++) {
>>          p[i] = ebcdic2ascii[(uint8_t)ebcdic[i]];
> 
> Making the passed len parameter a size_t makes sense; but using a
> size_t as an array iterator looks a bit unidiomatic... it's not wrong,
> though.

This is to silent the "-Wsign-conversion -Wsign-compare" warnings...
I am still not sure what is the best to do.

> Acked-by: Cornelia Huck <cohuck@redhat.com>

Thanks!

Phil.