diff --git a/src/event.c b/src/event.c
index d5bf967..cf68711 100644
--- a/src/event.c
+++ b/src/event.c
#define _GNU_SOURCE
#include <stdio.h>
+#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
struct remote_dev_info match, *dev_info;
if (status == 0) {
- char *end;
-
- /* It's ok to cast end between const and non-const since
- * we know it points to inside of name which is non-const */
- if (!g_utf8_validate(name, -1, (const char **) &end))
- *end = '\0';
+ if (!g_utf8_validate(name, -1, NULL)) {
+ int i;
+
+ /* Assume ASCII, and replace all non-ASCII with
+ * spaces */
+ for (i = 0; name[i] != '\0'; i++) {
+ if (!isascii(name[i]))
+ name[i] = ' ';
+ }
+ /* Remove leading and trailing whitespace characters */
+ g_strstrip(name);
+ }
write_device_name(local, peer, name);
}