aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2015-12-26 15:04:39 +0100
committerMattias Andrée <maandree@member.fsf.org>2015-12-26 15:04:39 +0100
commit2bcaff7589c7fe0816bb5f08b500fdc942c13d89 (patch)
treef97484715ac8ded22edbbad28aeaf84bf0c4d4b5 /src
parentcreate socket (diff)
downloadsat-2bcaff7589c7fe0816bb5f08b500fdc942c13d89.tar.gz
sat-2bcaff7589c7fe0816bb5f08b500fdc942c13d89.tar.bz2
sat-2bcaff7589c7fe0816bb5f08b500fdc942c13d89.tar.xz
marshalled arrays are not empty-element-terminated
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to 'src')
-rw-r--r--src/client.c3
-rw-r--r--src/satr.c8
2 files changed, 6 insertions, 5 deletions
diff --git a/src/client.c b/src/client.c
index 9df327e..c4f2987 100644
--- a/src/client.c
+++ b/src/client.c
@@ -59,7 +59,7 @@ send_command(enum command cmd, size_t n, const char *restrict msg)
size_t
measure_array(char *array[])
{
- size_t rc = 1;
+ size_t rc = 0;
for (; *array; array++)
rc += strlen(*array) + 1;
return rc * sizeof(char);
@@ -80,7 +80,6 @@ store_array(char *restrict storage, char *array[])
storage = stpcpy(storage, *array);
*storage++ = 0;
}
- *storage++ = 0;
return storage;
}
diff --git a/src/satr.c b/src/satr.c
index b3ebd62..d432343 100644
--- a/src/satr.c
+++ b/src/satr.c
@@ -63,16 +63,18 @@ main(int argc, char *argv[])
char *msg = NULL;
int i;
- if (argc > 0) argv0 = argv[0];
+ if (argc > 0)
+ argv0 = argv[0];
if (argc < 2)
goto run;
- if (!strcmp(argv[1], "--")
+ if (!strcmp(argv[1], "--"))
argv++, argc--;
for (i = 1; i < argc; i++)
if (argv[i][0] == '-')
usage();
- if (!(msg = malloc(n = measure_array(argv + 1))))
+ n = measure_array(argv + 1);
+ if (n ? !(msg = malloc(n)) : 0)
goto fail;
store_array(msg, argv + 1);