{"thread":{"id":"26661","subject":"[PATCH] transport-helper.c: fix check for size_t < 0","startedAt":"2011-03-04T19:28:34Z","lastAt":"2011-03-04T23:16:26Z","messageCount":3,"participants":["Nicolas Kaiser","Piotr Krukowiecki"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"162791","messageId":"20110304202834.2e74d56d@absol.kitzblitz","threadId":"26661","inReplyTo":null,"subject":"[PATCH] transport-helper.c: fix check for size_t < 0","fromName":"Nicolas Kaiser","fromEmail":"nikai@nikai.net","sentAt":"2011-03-04T19:28:34Z","receivedAt":"2011-03-04T19:28:34Z","isPatch":true,"sender":{"key":"nikai@nikai.net","avatar":"https://avatars.githubusercontent.com/u/494755?v=4"},"body":"'bytes' is unsigned of type size_t, and can't be negative.\nBut the assigned write() returns ssize_t, and -1 on error.\nFor testing < 0, 'bytes' needs to be of a signed type.\n\nSigned-off-by: Nicolas Kaiser <nikai@nikai.net>\n---\nTestsuite did not regress at my place.\n\n transport-helper.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 4e4754c..710b6f1 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -973,7 +973,7 @@ static int udt_do_read(struct unidirectional_transfer *t)\n  */\n static int udt_do_write(struct unidirectional_transfer *t)\n {\n-\tsize_t bytes;\n+\tint bytes;\n \n \tif (t->bufuse == 0)\n \t\treturn 0;\t/* Nothing to write. */\n@@ -989,7 +989,7 @@ static int udt_do_write(struct unidirectional_transfer *t)\n \t\tif (t->bufuse)\n \t\t\tmemmove(t->buf, t->buf + bytes, t->bufuse);\n \t\ttransfer_debug(\"Wrote %i bytes to %s (buffer now at %i)\",\n-\t\t\t(int)bytes, t->dest_name, (int)t->bufuse);\n+\t\t\tbytes, t->dest_name, (int)t->bufuse);\n \t}\n \treturn 0;\n }\n-- \n1.7.3.4\n"},{"id":"162793","messageId":"AANLkTimc_iLDXxrV=tfZc+_dCkpx6897Lh8sZxkwbgDo@mail.gmail.com","threadId":"26661","inReplyTo":"20110304202834.2e74d56d@absol.kitzblitz","subject":"Re: [PATCH] transport-helper.c: fix check for size_t < 0","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2011-03-04T20:20:46Z","receivedAt":"2011-03-04T20:20:46Z","isPatch":true,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"On Fri, Mar 4, 2011 at 8:28 PM, Nicolas Kaiser <nikai@nikai.net> wrote:\n> 'bytes' is unsigned of type size_t, and can't be negative.\n> But the assigned write() returns ssize_t, and -1 on error.\n> For testing < 0, 'bytes' needs to be of a signed type.\n\nYou are right that, but the fix should be to use ssize_t not  plain \"int\".\n(udt_do_read() correctly uses ssize_t)\n\nNot providing patch since the change is trivial.\n\n>\n> Signed-off-by: Nicolas Kaiser <nikai@nikai.net>\n> ---\n> Testsuite did not regress at my place.\n>\n>  transport-helper.c |    4 ++--\n>  1 files changed, 2 insertions(+), 2 deletions(-)\n>\n> diff --git a/transport-helper.c b/transport-helper.c\n> index 4e4754c..710b6f1 100644\n> --- a/transport-helper.c\n> +++ b/transport-helper.c\n> @@ -973,7 +973,7 @@ static int udt_do_read(struct unidirectional_transfer *t)\n>  */\n>  static int udt_do_write(struct unidirectional_transfer *t)\n>  {\n> -       size_t bytes;\n> +       int bytes;\n>\n>        if (t->bufuse == 0)\n>                return 0;       /* Nothing to write. */\n> @@ -989,7 +989,7 @@ static int udt_do_write(struct unidirectional_transfer *t)\n>                if (t->bufuse)\n>                        memmove(t->buf, t->buf + bytes, t->bufuse);\n>                transfer_debug(\"Wrote %i bytes to %s (buffer now at %i)\",\n> -                       (int)bytes, t->dest_name, (int)t->bufuse);\n> +                       bytes, t->dest_name, (int)t->bufuse);\n>        }\n>        return 0;\n>  }\n> --\n> 1.7.3.4\n\n\n-- \nPiotrek\n"},{"id":"162802","messageId":"20110305001626.3b6c507d@absol.kitzblitz","threadId":"26661","inReplyTo":"AANLkTimc_iLDXxrV=tfZc+_dCkpx6897Lh8sZxkwbgDo@mail.gmail.com","subject":"[PATCH] transport-helper.c: fix check for size_t < 0 v2","fromName":"Nicolas Kaiser","fromEmail":"nikai@nikai.net","sentAt":"2011-03-04T23:16:26Z","receivedAt":"2011-03-04T23:16:26Z","isPatch":true,"sender":{"key":"nikai@nikai.net","avatar":"https://avatars.githubusercontent.com/u/494755?v=4"},"body":"'bytes' is unsigned of type size_t, and can't be negative.\nBut the assigned write() returns ssize_t, and -1 on error.\nFor testing < 0, 'bytes' needs to be of a signed type.\n\nSigned-off-by: Nicolas Kaiser <nikai@nikai.net>\n---\n* Piotr Krukowiecki <piotr.krukowiecki@gmail.com>:\n> You are right that, but the fix should be to use ssize_t not  plain \"int\".\n> (udt_do_read() correctly uses ssize_t)\n\nIndeed, thanks. Here's a version with ssize_t.\nTestsuite did not regress at my place.\n\n transport-helper.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 4e4754c..ba06b70 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -973,7 +973,7 @@ static int udt_do_read(struct unidirectional_transfer *t)\n  */\n static int udt_do_write(struct unidirectional_transfer *t)\n {\n-\tsize_t bytes;\n+\tssize_t bytes;\n \n \tif (t->bufuse == 0)\n \t\treturn 0;\t/* Nothing to write. */\n-- \n1.7.3.4\n"}]}