Mercurial > mplayer.hg
changeset 33156:9ac31195a5e0
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.
author | reimar |
---|---|
date | Sat, 09 Apr 2011 15:09:06 +0000 |
parents | 16e5b7f9ddb8 |
children | 8073274a9ff2 |
files | udp_sync.c |
diffstat | 1 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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;