From: git Date: Tue, 17 Feb 2026 18:58:29 +0000 (-0500) Subject: fixed a bug with -# not converting to -s# on some platforms X-Git-Url: https://git.datadissipation.net/?a=commitdiff_plain;h=5975dfc0d7eddde025db78dc38525eb158386faa;p=ust.git fixed a bug with -# not converting to -s# on some platforms --- diff --git a/ust.c b/ust.c index 56d0482..9c2c57f 100644 --- a/ust.c +++ b/ust.c @@ -13,7 +13,7 @@ #ifdef __linux__ #include #include -#else +#else /* needed for termios2, which is itself needed for non-standard bauds */ #include #endif @@ -61,7 +61,7 @@ static void die(int code, const char *msg, ...); static struct termios cntrl, origterm = {0}, newterm = {0}; #endif -static const unsigned int uintmax = ~(unsigned int)0; +static const unsigned int uintmax = ~(unsigned int)0; /* unsigned -1 to return on error */ static struct timespec wts; static char *writebuff = NULL; static char *readbuff = NULL; @@ -353,7 +353,6 @@ writeport(void *unused) int escape = 0; - Args bsargs, nocrargs, nolfargs, lfincrargs; bsargs.sizem = wbuffsz; nocrargs = nolfargs = lfincrargs = bsargs; @@ -429,7 +428,6 @@ readport(void *unused) lfincrargs.find = CR; lfincrargs.input = LF; lfincrargs.offset = 1; crinlfargs.find = LF; crinlfargs.input = CR; crinlfargs.offset = -1; - /* disable stdout buffering */ setvbuf(stdout, NULL, _IONBF, 0); @@ -749,17 +747,16 @@ die(int code, const char *msg, ...) int main(int argc, char **argv) { + char *t = NULL; + /* glibc's `asprintf()` won't set the string to NULL on failure automatically */ for (int i = 1; i < argc; i++ ) { if (argv[i][0] == '-' && argv[i][1] >= '0' && argv[i][1] <= '9') { - char *t = NULL; - /* glibc's `asprintf()` won't set the string to NULL on failure automatically */ asprintf(&t, "-s%s", argv[i] + 1); if (!t) { fprintf(stderr, "cannot convert -# to -s#\n"); break; } argv[i] = t; - free(t); } } @@ -890,9 +887,13 @@ main(int argc, char **argv) argv[0]); break; } - - } + /* + * not the best practice, but in order for this `free()` + * to not get executed ust needs to be killed, + * which means the OS *should* free the memory + */ + free(t); if (!rxspdset) ispeed = ospeed;