Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions simple_uart.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#ifndef PATH_MAX
#define PATH_MAX MAX_PATH
#endif /* PATH_MAX */
#endif /* _MSC_VER */

#define _GNU_SOURCE
#include <ctype.h>
#include <errno.h>
Expand Down Expand Up @@ -252,8 +259,18 @@ static int simple_uart_set_config(struct simple_uart *sc, int speed, const char
} else {
options.fRtsControl = RTS_CONTROL_DISABLE;
}
// XON/XOFF
if (HAS_OPTION('X')) {
options.fOutX = TRUE;
options.fInX = TRUE;
} else {
options.fOutX = FALSE;
options.fInX = FALSE;
}

/* mandatory options */
options.fBinary = TRUE;
options.fDtrControl = FALSE;
/* assign to port */
if (!SetCommState(sc->port, &options))
return win32_errno();
Expand Down Expand Up @@ -742,14 +759,14 @@ int simple_uart_describe(const char *uart, char *description, size_t max_desc_le
int simple_uart_set_logfile(struct simple_uart *uart, const char *logfile, ...)
{
va_list ap;
char *buffer;
char buffer[PATH_MAX];
int len;

if (!uart || !logfile)
return -EINVAL;

va_start(ap, logfile);
len = vasprintf(&buffer, logfile, ap);
len = vsprintf(buffer, logfile, ap);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be vsnprintf(buffer, sizeof(buffer)...?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would be more safe. I will fix this.

va_end(ap);
if (len < 0)
return -errno;
Expand All @@ -760,10 +777,8 @@ int simple_uart_set_logfile(struct simple_uart *uart, const char *logfile, ...)
uart->logfile = fopen(buffer, "a");
if (!uart->logfile) {
int e = -errno;
free(buffer);
return e;
}
free(buffer);
return 0;
}

Expand Down