* [Qemu-devel] [PATCH] cutils: Use int64_t instead of ssize_t for strtosz()
@ 2011-01-10 10:29 Stefan Hajnoczi
2011-01-10 10:33 ` [Qemu-devel] " Jes Sorensen
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hajnoczi @ 2011-01-10 10:29 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Jes Sorensen, Stefan Hajnoczi
The strtosz() function parses byte count strings and converts K, M, G
units. The ssize_t type is not appropriate because block devices need
64-bit range even on 32-bit hosts. Switch from ssize_t to int64_t.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
cutils.c | 8 ++++----
monitor.c | 2 +-
qemu-common.h | 4 ++--
qemu-img.c | 2 +-
vl.c | 4 ++--
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/cutils.c b/cutils.c
index 7984bc1..7f1c05e 100644
--- a/cutils.c
+++ b/cutils.c
@@ -291,9 +291,9 @@ int fcntl_setfl(int fd, int flag)
* value must be terminated by whitespace, ',' or '\0'. Return -1 on
* error.
*/
-ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
+int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
{
- ssize_t retval = -1;
+ int64_t retval = -1;
char *endptr, c, d;
int mul_required = 0;
double val, mul, integral, fraction;
@@ -365,7 +365,7 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
goto fail;
}
}
- if ((val * mul >= ~(size_t)0) || val < 0) {
+ if ((val * mul >= ~(uint64_t)0) || val < 0) {
goto fail;
}
retval = val * mul;
@@ -378,7 +378,7 @@ fail:
return retval;
}
-ssize_t strtosz(const char *nptr, char **end)
+int64_t strtosz(const char *nptr, char **end)
{
return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB);
}
diff --git a/monitor.c b/monitor.c
index f258000..fcdae15 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4162,7 +4162,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
break;
case 'o':
{
- ssize_t val;
+ int64_t val;
char *end;
while (qemu_isspace(*p)) {
diff --git a/qemu-common.h b/qemu-common.h
index 63d9943..cce6e61 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -158,8 +158,8 @@ int fcntl_setfl(int fd, int flag);
#define STRTOSZ_DEFSUFFIX_MB 'M'
#define STRTOSZ_DEFSUFFIX_KB 'K'
#define STRTOSZ_DEFSUFFIX_B 'B'
-ssize_t strtosz(const char *nptr, char **end);
-ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
+int64_t strtosz(const char *nptr, char **end);
+int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
/* path.c */
void init_paths(const char *prefix);
diff --git a/qemu-img.c b/qemu-img.c
index afd9ed2..6af2a4c 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -320,7 +320,7 @@ static int img_create(int argc, char **argv)
/* Get image size, if specified */
if (optind < argc) {
- ssize_t sval;
+ int64_t sval;
sval = strtosz_suffix(argv[optind++], NULL, STRTOSZ_DEFSUFFIX_B);
if (sval < 0) {
error_report("Invalid image size specified! You may use k, M, G or "
diff --git a/vl.c b/vl.c
index 78fcef1..93425f4 100644
--- a/vl.c
+++ b/vl.c
@@ -804,7 +804,7 @@ static void numa_add(const char *optarg)
if (get_param_value(option, 128, "mem", optarg) == 0) {
node_mem[nodenr] = 0;
} else {
- ssize_t sval;
+ int64_t sval;
sval = strtosz(option, NULL);
if (sval < 0) {
fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
@@ -2245,7 +2245,7 @@ int main(int argc, char **argv, char **envp)
exit(0);
break;
case QEMU_OPTION_m: {
- ssize_t value;
+ int64_t value;
value = strtosz(optarg, NULL);
if (value < 0) {
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] Re: [PATCH] cutils: Use int64_t instead of ssize_t for strtosz()
2011-01-10 10:29 [Qemu-devel] [PATCH] cutils: Use int64_t instead of ssize_t for strtosz() Stefan Hajnoczi
@ 2011-01-10 10:33 ` Jes Sorensen
2011-01-10 10:50 ` Stefan Hajnoczi
0 siblings, 1 reply; 3+ messages in thread
From: Jes Sorensen @ 2011-01-10 10:33 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Kevin Wolf, qemu-devel
On 01/10/11 11:29, Stefan Hajnoczi wrote:
> The strtosz() function parses byte count strings and converts K, M, G
> units. The ssize_t type is not appropriate because block devices need
> 64-bit range even on 32-bit hosts. Switch from ssize_t to int64_t.
Hmmm I think this is identical to the patch I posted last week :)
Cheers,
Jes
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] Re: [PATCH] cutils: Use int64_t instead of ssize_t for strtosz()
2011-01-10 10:33 ` [Qemu-devel] " Jes Sorensen
@ 2011-01-10 10:50 ` Stefan Hajnoczi
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2011-01-10 10:50 UTC (permalink / raw)
To: Jes Sorensen; +Cc: Kevin Wolf, Stefan Hajnoczi, qemu-devel
On Mon, Jan 10, 2011 at 10:33 AM, Jes Sorensen <Jes.Sorensen@redhat.com> wrote:
> On 01/10/11 11:29, Stefan Hajnoczi wrote:
>> The strtosz() function parses byte count strings and converts K, M, G
>> units. The ssize_t type is not appropriate because block devices need
>> 64-bit range even on 32-bit hosts. Switch from ssize_t to int64_t.
>
> Hmmm I think this is identical to the patch I posted last week :)
Sorry for the duplication. Someone on IRC discovered the issue and I
wrote up the patch this morning. No worries :).
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-01-10 10:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-10 10:29 [Qemu-devel] [PATCH] cutils: Use int64_t instead of ssize_t for strtosz() Stefan Hajnoczi
2011-01-10 10:33 ` [Qemu-devel] " Jes Sorensen
2011-01-10 10:50 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).