pc-bios/s390-ccw: size_t should be unsigned
PATCH 1/1 pc-bios/s390-ccw: size_t should be unsigned
"size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use this convention in the s390-ccw firmware to avoid confusion. I checked the sources, and apart from one spot in libc.c (which now uses ssize_t with this patch), the code should all be fine with this change.
--- pc-bios/s390-ccw/libc.c | 2 +- pc-bios/s390-ccw/libc.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
pc-bios/s390-ccw/libc.c +1 -1
@@ -63,7 +63,7 @@ uint64_t atoui(const char *str)*/ char *uitoa (uint64_t num,char *str,size_t len) { -size_t num_idx =1 ;/* account for NUL */ +ssize_t num_idx =1 ;/* account for NUL */ uint64_t tmp = num;IPL_assert (str !=NULL ,"uitoa: no space allocated to store string" );
pc-bios/s390-ccw/libc.h +2 -1
@@ -12,7 +12,8 @@#ifndef S390_CCW_LIBC_H #define S390_CCW_LIBC_H -typedef long size_t ; +typedef unsigned long size_t ; +typedef signed long ssize_t ;typedef int bool ;typedef unsigned char uint8_t ;typedef unsigned short uint16_t ;
Signature · 1 line
1.8.3.1
Quoted 8 lines · Thomas Huth
"
size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use this convention in the s390-ccw firmware to avoid confusion. I checked the sources, and apart from one spot inlibc.c(which now usesssize_twith this patch), the code should all be fine with this change.Signed-off-by Thomas Huth <[email protected]>
Quoted 33 lines
--- pc-bios/s390-ccw/libc.c | 2 +- pc-bios/s390-ccw/libc.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)pc-bios/s390-ccw/libc.c +1
-1@@ -63,7 +63,7 @@ uint64_t atoui(const char *str)*/ char *uitoa (uint64_t num,char *str,size_t len) { -size_t num_idx =1 ;/* account for NUL */ +ssize_t num_idx =1 ;/* account for NUL */ uint64_t tmp = num;IPL_assert (str !=NULL ,"uitoa: no space allocated to store string" );pc-bios/s390-ccw/libc.h +2
-1@@ -12,7 +12,8 @@#ifndef S390_CCW_LIBC_H #define S390_CCW_LIBC_H -typedef long size_t ; +typedef unsigned long size_t ; +typedef signed long ssize_t ;typedef int bool ;typedef unsigned char uint8_t ;typedef unsigned short uint16_t ;
Quoted 32 lines · Thomas Huth
"
size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use this convention in the s390-ccw firmware to avoid confusion. I checked the sources, and apart from one spot inlibc.c(which now usesssize_twith this patch), the code should all be fine with this change.Signed-off-by Thomas Huth <[email protected]>--- pc-bios/s390-ccw/libc.c | 2 +- pc-bios/s390-ccw/libc.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)pc-bios/s390-ccw/libc.c +1
-1@@ -63,7 +63,7 @@ uint64_t atoui(const char *str)*/ char *uitoa (uint64_t num,char *str,size_t len) { -size_t num_idx =1 ;/* account for NUL */ +ssize_t num_idx =1 ;/* account for NUL */ uint64_t tmp = num;IPL_assert (str !=NULL ,"uitoa: no space allocated to store string" );pc-bios/s390-ccw/libc.h +0
-0
pc-bios/s390-ccw/libc.h line 19
Quoted 9 lines
pc-bios/s390-ccw/libc.h +2
-1@@ -12,7 +12,8 @@#ifndef S390_CCW_LIBC_H #define S390_CCW_LIBC_H -typedef long size_t ; +typedef unsigned long size_t ; +typedef signed long ssize_t ;typedef int bool ;typedef unsigned char uint8_t ;typedef unsigned short uint16_t ;
Looks good to me as well.
If another r-b is even necessary:
Signature · 2 lines
Respectfully, - Collin Walling
Quoted 2 lines · Thomas Huth
"
size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use this
The first sentence sounds like ssize_t is too a type defined by some C standard. Is it or does ssize_t come form somewhere else? I find negative size a little difficult conceptually.
Quoted 7 lines
convention in the s390-ccw firmware to avoid confusion. I checked the sources, and apart from one spot in
libc.c(which now usesssize_twith this patch), the code should all be fine with this change.Signed-off-by Thomas Huth <[email protected]>---
This is certainly an improvement over the confusing signed size_t, so:
BTW The stuff behind the buglink is a bit misleading. The description states the problem as can't escape loop (IMHO) and the bug status say 'confirmed'.
What actually happened is that it turned out the problem initially reported, was not existent. Yet the bug report helped us find another problem:
confusing names.
To complicate understanding even further, the comments on the bug only contain this realization hidden behind a link.
It probably does not matter though.
Quoted 9 lines · Halil Pasic
Quoted 2 lines · Thomas Huth
"
size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use thisThe first sentence sounds like
ssize_tis too a type defined by some C standard. Is it or doesssize_tcome form somewhere else? I find negative size a little difficult conceptually.
I think ssize_t is from POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
"Used for a count of bytes or an error indication".
thanks
-- PMM
Quoted 8 lines · Halil Pasic
Quoted 2 lines · Thomas Huth
"
size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use thisThe first sentence sounds like
ssize_tis too a type defined by some C standard. Is it or doesssize_tcome form somewhere else?
Arrr, seems like ssize_t is rather coming from POSIX than from the C standard, thanks for the hint. I'll rephrase the first sentence to:
"size_t" should be an unsigned type according to the C standard, and most libc implementations provide a signed counterpart called "ssize_t".
OK?
Quoted 11 lines
Quoted 7 lines
convention in the s390-ccw firmware to avoid confusion. I checked the sources, and apart from one spot in
libc.c(which now usesssize_twith this patch), the code should all be fine with this change.Signed-off-by Thomas Huth <[email protected]>---
This is certainly an improvement over the confusing signed
size_t, so:Acked-by Halil Pasic <[email protected]>
Thanks!
Quoted 7 lines
BTW The stuff behind the buglink is a bit misleading. The description states the problem as can't escape loop (IMHO) and the bug status say 'confirmed'.
What actually happened is that it turned out the problem initially reported, was not existent. Yet the bug report helped us find another problem:
confusing names.
Ok, I've updated the bug title.
Quoted 2 lines
To complicate understanding even further, the comments on the bug only contain this realization hidden behind a link.
Oh well, yes, the bridge between the bugtracker and the mailing list really su...ffers from many problems. Normally replies should show up in the bug tracker as well, but in this case the bridge just failed.
Thomas
Quoted 7 lines · Thomas Huth
Quoted 6 lines · Halil Pasic
Quoted 2 lines · Thomas Huth
"
size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use thisThe first sentence sounds like
ssize_tis too a type defined by some C standard. Is it or doesssize_tcome form somewhere else?
Quoted 8 lines
Arrr, seems like
ssize_tis rather coming from POSIX than from the C standard, thanks for the hint. I'll rephrase the first sentence to:"
size_t" should be an unsigned type according to the C standard, and most libc implementations provide a signed counterpart called "ssize_t".OK?
This ssize_t seems to be an rather interesting type. For instance POSIX says """size_t
Used for sizes of objects.ssize_t
Used for a count of bytes or an error indication.
"""
and
"""
The type ssize_t shall be capable of storing values at least in the range [-1, {SSIZE_MAX}]. """
And it does not mandate SSIZE_MIN in limits (but of course mandates SSIZE_MAX.
I don't like this 'counterpart' word here, because AFAIU these don't have to be counterparts in any sense. That is SSIZE_MAX << SIZE_MAX is possible for example. I'm not sure about the every positive has a negative thing, but that's not important here.
The code in question kind of uses both signed and unsigned size for the same (the string). We even have a signed to unsigned comparison which could result in warnings. I still think the change is OK in practice, but maybe avoiding introducing ssize_t (until we really need it) is a better course of action. I think uitoa can be easily rewritten so it does not need the ssize_t.
How about that?
Regards,
Halil
Quoted 33 lines · Halil Pasic
Quoted 5 lines
Quoted 5 lines · Thomas Huth
Quoted 2 lines
"
size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use thisThe first sentence sounds like
ssize_tis too a type defined by some C standard. Is it or doesssize_tcome form somewhere else?Quoted 8 lines
Arrr, seems like
ssize_tis rather coming from POSIX than from the C standard, thanks for the hint. I'll rephrase the first sentence to:"
size_t" should be an unsigned type according to the C standard, and most libc implementations provide a signed counterpart called "ssize_t".OK?
This
ssize_tseems to be an rather interesting type. For instance POSIX says """size_t
Used for sizes of objects.ssize_t
Used for a count of bytes or an error indication.
"""
and
"""
The typessize_tshall be capable of storing values at least in the range [-1, {SSIZE_MAX}]. """And it does not mandate
SSIZE_MINin limits (but of course mandatesSSIZE_MAX.I don't like this 'counterpart' word here, because AFAIU these don't have to be counterparts in any sense. That is
SSIZE_MAX<<SIZE_MAXis possible for example. I'm not sure about the every positive has a negative thing, but that's not important here.
Quoted 8 lines
The code in question kind of uses both signed and unsigned size for the same (the string). We even have a signed to unsigned comparison which could result in warnings. I still think the change is OK in practice, but maybe avoiding introducing
ssize_t(until we really need it) is a better course of action. I think uitoa can be easily rewritten so it does not need thessize_t.How about that?
This seems clever indeed.
Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Halil Pasic
Quoted 5 lines
Quoted 5 lines · Thomas Huth
Quoted 2 lines
"
size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use thisThe first sentence sounds like
ssize_tis too a type defined by some C standard. Is it or doesssize_tcome form somewhere else?Quoted 8 lines
Arrr, seems like
ssize_tis rather coming from POSIX than from the C standard, thanks for the hint. I'll rephrase the first sentence to:"
size_t" should be an unsigned type according to the C standard, and most libc implementations provide a signed counterpart called "ssize_t".OK?
This
ssize_tseems to be an rather interesting type. For instance POSIX says """size_t
Used for sizes of objects.ssize_t
Used for a count of bytes or an error indication.
"""
and
"""
The typessize_tshall be capable of storing values at least in the range [-1, {SSIZE_MAX}]. """And it does not mandate
SSIZE_MINin limits (but of course mandatesSSIZE_MAX.I don't like this 'counterpart' word here, because AFAIU these don't have to be counterparts in any sense. That is
SSIZE_MAX<<SIZE_MAXis possible for example. I'm not sure about the every positive has a negative thing, but that's not important here.The code in question kind of uses both signed and unsigned size for the same (the string). We even have a signed to unsigned comparison which could result in warnings. I still think the change is OK in practice, but maybe avoiding introducing
ssize_t(until we really need it) is a better course of action. I think uitoa can be easily rewritten so it does not need thessize_t.
Quoted 4 lines
Quoted 1 line
How about that?
This seems clever indeed.
This whole issue stems from my misuse of size_t in the first place. If it makes things easier, let's just make num_idx of type "signed long".
After reading this discussion, I think it makes sense to drop ssize_t. No need to make it available for just one function unless there are strong claims to also use this type elsewhere in the pc-bios (I can't find any).
Signature · 2 lines
Respectfully, - Collin Walling
Quoted 47 lines · On Fri, 13 Apr 2018 14:09:55 -0400 Collin Walling <[email protected]> wrote:
Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Halil Pasic
Quoted 5 lines
Quoted 5 lines · Thomas Huth
Quoted 2 lines
"
size_t" should be an unsigned type - the signed counterpart is called "ssize_t" in the C standard instead. Thus we should also use thisThe first sentence sounds like
ssize_tis too a type defined by some C standard. Is it or doesssize_tcome form somewhere else?Quoted 8 lines
Arrr, seems like
ssize_tis rather coming from POSIX than from the C standard, thanks for the hint. I'll rephrase the first sentence to:"
size_t" should be an unsigned type according to the C standard, and most libc implementations provide a signed counterpart called "ssize_t".OK?
This
ssize_tseems to be an rather interesting type. For instance POSIX says """size_t
Used for sizes of objects.ssize_t
Used for a count of bytes or an error indication.
"""
and
"""
The typessize_tshall be capable of storing values at least in the range [-1, {SSIZE_MAX}]. """And it does not mandate
SSIZE_MINin limits (but of course mandatesSSIZE_MAX.I don't like this 'counterpart' word here, because AFAIU these don't have to be counterparts in any sense. That is
SSIZE_MAX<<SIZE_MAXis possible for example. I'm not sure about the every positive has a negative thing, but that's not important here.The code in question kind of uses both signed and unsigned size for the same (the string). We even have a signed to unsigned comparison which could result in warnings. I still think the change is OK in practice, but maybe avoiding introducing
ssize_t(until we really need it) is a better course of action. I think uitoa can be easily rewritten so it does not need thessize_t.Quoted 4 lines
Quoted 1 line
How about that?
This seems clever indeed.
Quoted 7 lines
This whole issue stems from my misuse of
size_tin the first place. If it makes things easier, let's just makenum_idxof type "signed long".After reading this discussion, I think it makes sense to drop
ssize_t. No need to make it available for just one function unless there are strong claims to also use this type elsewhere in the pc-bios (I can't find any).
+1 to just using signed long. Let's not make this needlessly complicated.
Quoted 12 lines · Halil Pasic
This
ssize_tseems to be an rather interesting type. For instance POSIX says """size_t
Used for sizes of objects.ssize_t
Used for a count of bytes or an error indication.
"""
and
"""
The typessize_tshall be capable of storing values at least in the range [-1, {SSIZE_MAX}]. """
Quoted 1 line
And it does not mandate
SSIZE_MINin limits (but of course mandatesSSIZE_MAX.
I've tried to get POSIX to tighten things to require that 'size_t' and 'ssize_t' must have the same rank, so that you can sanely use printf("%zd",(ssize_t)val), but we are not there yet.
Quoted 5 lines
I don't like this 'counterpart' word here, because AFAIU these don't have to be counterparts in any sense. That is
SSIZE_MAX<<SIZE_MAXis possible for example. I'm not sure about the every positive has a negative thing, but that's not important here.
Indeed, until the POSIX wording is tightened, it is technically possible (but a very poor quality of implementation, and none of qemu's compilation platforms fall in that category) that ssize_t has a different rank than size_t (whether or not they also have a different width).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org