[MPlayer-cvslog] r33243 - trunk/udp_sync.c

reimar subversion at mplayerhq.hu
Sat Apr 9 17:09:07 CEST 2011


Author: reimar
Date: Sat Apr  9 17:09:06 2011
New Revision: 33243

Log:
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.

Modified:
   trunk/udp_sync.c

Modified: trunk/udp_sync.c
==============================================================================
--- trunk/udp_sync.c	Sat Apr  9 16:55:22 2011	(r33242)
+++ trunk/udp_sync.c	Sat Apr  9 17:09:06 2011	(r33243)
@@ -105,6 +105,7 @@ static int get_udp(int blocking, double 
 
     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 @@ static int get_udp(int blocking, double 
         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;


More information about the MPlayer-cvslog mailing list