# HG changeset patch # User reimar # Date 1302361746 0 # Node ID 9ac31195a5e0db8a6a83eeb3fd190c90cb831d8c # Parent 16e5b7f9ddb8eee1785daebf2fa0a38d78396844 Use strtod instead of sscanf, it is both much faster and allows for easier error checking. Also do that error checking and print a message if what we received is not a proper number and ignore the message. diff -r 16e5b7f9ddb8 -r 9ac31195a5e0 udp_sync.c --- a/udp_sync.c Sat Apr 09 14:55:22 2011 +0000 +++ b/udp_sync.c Sat Apr 09 15:09:06 2011 +0000 @@ -105,6 +105,7 @@ while (-1 != (n = recvfrom(sockfd, mesg, sizeof(mesg)-1, 0, NULL, NULL))) { + char *end; // flush out any further messages so we don't get behind if (chars_received == -1) set_blocking(sockfd, 0); @@ -113,7 +114,11 @@ mesg[chars_received] = 0; if (strcmp(mesg, "bye") == 0) return 1; - sscanf(mesg, "%lf", master_position); + *master_position = strtod(mesg, &end); + if (*end) { + mp_msg(MSGT_CPLAYER, MSGL_WARN, "Could not parse udp string!\n"); + *master_position = MP_NOPTS_VALUE; + } } return 0;