[rtmpdump] patch: gcc printf attributes

Peter Miller pmiller at opensource.org.au
Fri Apr 8 16:08:38 CEST 2011


This patch annotates the log function prototypes so that gcc knows they
are expecting printf(3) style arguments.  This allows gcc to check them.
All the errors so found have been fixed.

-- 
Regards
Peter Miller <pmiller at opensource.org.au>
/\/\*        http://miller.emu.id.au/pmiller/

PGP public key ID: 1024D/D0EDB64D
fingerprint = AD0A C5DF C426 4F03 5D53  2BDB 18D8 A4E2 D0ED B64D
See http://www.keyserver.net or any PGP keyserver for public key.

"Real Programmers don't play tennis, or any other sport which requires
you to change clothes.  Mountain climbing is OK, and Real Programmers
wear their climbing boots to work in case a mountain should suddenly
spring up in the middle of the computer room."
-------------- next part --------------
MIME-Version: 1.0
Content-Type: application/aegis-patch
Subject: rtmpdump.2.3 - printf function attributes
Content-Name: rtmpdump.2.3.C023.patch
Content-Disposition: attachment; filename=rtmpdump.2.3.C023.patch
X-Aegis-Project-Name: rtmpdump.2.3
X-Aegis-Change-Number: 23

#	
#	This change set annotates the log function prototypes so that gcc
#	knows they are expecting printf(3) style arguments.  This allows gcc
#	to check them.  All the errors so found have been fixed.
#	
# Aegis-Change-Set-Begin
# QlpoMzFBWSZTWe34A5gAAV5fgAAQUGf/6iACBAq/79/qQAK8YKYYAlEpgZKeJPTJjJT1P0UD
# QAwamEA0TJJ6k8pmUyPKPUGnppBgAGjTQBk0BoMgNASRNE0IwptI9UG01PKejRqaDJoU13oX
# wgYBPIB0F5NCOPlxEP1YGYTIGQe62Hu/xE6vP9OQ/n6VpdW+10FLZUIQaXdo7NbRYCOvjtb8
# SOWe66MbxmPZi9Isu+UD8eUV6c4jnGXO560gWp9ExFFSUykV0sGZPbdLv23/FU5EB4CK0K/3
# s8s52WKT23UWFal128e0WvDfvYaVoChIqtlBo01qX51xpcoiE8Ngj1nLMRTQHgyLWd0ESjdT
# ZXQtrLUqJTXOStVWmeGthIWvO9jS5NOsVrW6aTpjD81aCZBBXkuSzKmHk2gWFJPIqaHSxo9p
# nUjZwD/6YMjPbo4IQdIQcEkiXZ37BP862yqzIPTfr3R3tGu7fu0saHzMUed44cAnCPo4Dl7D
# PiTgPlzR2D2DLVTZGvjiuyce0vCht7gPId6DqHXMEG8mIeqWJa34cR9YyWzgNywLir/0GWID
# zkIL3Gsrl1dfTNNyrunx4UsWHNvPIr+ED08OiAuEEDfpHRZJC6K2Lxzsvz0RUCDUCjWjSFNl
# /V89Vj9fcwxxqcl+ZnG1heNYjeGiTNltXi910a3UY4RJZI7ZZPmNkC4HoG2q+LJCKAyd8N7c
# 6FGKdTcJy8Q3gg1SIoVmOheTnAxsvHLKv69yR6hn8zs6xVoQbs3ogykwE1vBMxlzQTW1VO/z
# rCa3Q5IMCYk19WppYgnOxLpo+OmZJGwtyQZfXq+Jw3mpppJ8fCgZBVbcD2utHaeKBxtudWSM
# sKA8pBKelAxrEM9dWgtRnheOkYIIu2jqy82Taiy2iO77algjFBbYOIrLOr0MoRVBgVEH/F3J
# FOFCQ7fgDmA=
# Aegis-Change-Set-End
#
Index: Makefile
--- Makefile
+++ Makefile
@@ -21,7 +21,7 @@
 
 DEF=-DRTMPDUMP_VERSION=\"$(VERSION)\" $(CRYPTO_DEF) $(XDEF)
 OPT=-O2
-CFLAGS=-Wall $(XCFLAGS) $(INC) $(DEF) $(OPT)
+CFLAGS=-Wall -Werror $(XCFLAGS) $(INC) $(DEF) $(OPT)
 LDFLAGS=-Wall $(XLDFLAGS)
 
 bindir=$(prefix)/bin
Index: librtmp/Makefile
--- librtmp/Makefile
+++ librtmp/Makefile
@@ -67,7 +67,7 @@
 
 DEF=-DRTMPDUMP_VERSION=\"$(VERSION)\" $(CRYPTO_DEF) $(XDEF)
 OPT=-O2
-CFLAGS=-Wall $(XCFLAGS) $(INC) $(DEF) $(OPT) $(SO_DEF)
+CFLAGS=-Wall -Werror $(XCFLAGS) $(INC) $(DEF) $(OPT) $(SO_DEF)
 LDFLAGS=$(XLDFLAGS)
 
 
Index: librtmp/amf.c
--- librtmp/amf.c
+++ librtmp/amf.c
@@ -586,8 +586,9 @@
     case AMF3_ARRAY:
     case AMF3_BYTE_ARRAY:
     default:
-      RTMP_Log(RTMP_LOGDEBUG, "%s - AMF3 unknown/unsupported datatype 0x%02x, @0x%08X",
-	  __FUNCTION__, (unsigned char)(*pBuffer), pBuffer);
+      RTMP_Log(RTMP_LOGDEBUG,
+               "%s - AMF3 unknown/unsupported datatype 0x%02x, @0x%08lX",
+	       __FUNCTION__, (unsigned char)(*pBuffer), (unsigned long)pBuffer);
       return -1;
     }
 
@@ -772,8 +773,8 @@
 	break;
       }
     default:
-      RTMP_Log(RTMP_LOGDEBUG, "%s - unknown datatype 0x%02x, @0x%08X", __FUNCTION__,
-	  prop->p_type, pBuffer - 1);
+      RTMP_Log(RTMP_LOGDEBUG, "%s - unknown datatype 0x%02x, @0x%08lX",
+               __FUNCTION__, prop->p_type, (unsigned long)(pBuffer - 1));
       return -1;
     }
 
Index: librtmp/log.h
--- librtmp/log.h
+++ librtmp/log.h
@@ -38,6 +38,12 @@
 #undef NODEBUG
 #endif
 
+#ifdef __GNUC__
+#define RTMP_ATTR_PRINTF(a, b) __attribute__((__format__(printf, a, b)))
+#else
+#define RTMP_ATTR_PRINTF(a, b)
+#endif
+
 typedef enum
 { RTMP_LOGCRIT=0, RTMP_LOGERROR, RTMP_LOGWARNING, RTMP_LOGINFO,
   RTMP_LOGDEBUG, RTMP_LOGDEBUG2, RTMP_LOGALL
@@ -48,9 +54,9 @@
 typedef void (RTMP_LogCallback)(int level, const char *fmt, va_list);
 void RTMP_LogSetCallback(RTMP_LogCallback *cb);
 void RTMP_LogSetOutput(FILE *file);
-void RTMP_LogPrintf(const char *format, ...);
-void RTMP_LogStatus(const char *format, ...);
-void RTMP_Log(int level, const char *format, ...);
+void RTMP_LogPrintf(const char *format, ...) RTMP_ATTR_PRINTF(1, 2);
+void RTMP_LogStatus(const char *format, ...) RTMP_ATTR_PRINTF(1, 2);
+void RTMP_Log(int level, const char *format, ...) RTMP_ATTR_PRINTF(2, 3);
 void RTMP_LogHex(int level, const uint8_t *data, unsigned long len);
 void RTMP_LogHexString(int level, const uint8_t *data, unsigned long len);
 void RTMP_LogSetLevel(RTMP_LogLevel lvl);
Index: librtmp/rtmp.c
--- librtmp/rtmp.c
+++ librtmp/rtmp.c
@@ -186,7 +186,8 @@
   RTMP_Log(RTMP_LOGDEBUG,
       "RTMP PACKET: packet type: 0x%02x. channel: 0x%02x. info 1: %d info 2: %d. Body size: %lu. body: 0x%02x",
       p->m_packetType, p->m_nChannel, p->m_nTimeStamp, p->m_nInfoField2,
-      p->m_nBodySize, p->m_body ? (unsigned char)p->m_body[0] : 0);
+      (unsigned long)p->m_nBodySize,
+      p->m_body ? (unsigned char)p->m_body[0] : 0);
 }
 
 int
@@ -363,7 +364,7 @@
     RTMP_Log(RTMP_LOGDEBUG, "StopTime      : %d msec", dStop);
 
   RTMP_Log(RTMP_LOGDEBUG, "live     : %s", bLiveStream ? "yes" : "no");
-  RTMP_Log(RTMP_LOGDEBUG, "timeout  : %d sec", timeout);
+  RTMP_Log(RTMP_LOGDEBUG, "timeout  : %d sec", (int)timeout);
 
 #ifdef CRYPTO
   if (swfSHA256Hash != NULL && swfSize > 0)
@@ -372,7 +373,7 @@
       r->Link.SWFSize = swfSize;
       RTMP_Log(RTMP_LOGDEBUG, "SWFSHA256:");
       RTMP_LogHex(RTMP_LOGDEBUG, r->Link.SWFHash, sizeof(r->Link.SWFHash));
-      RTMP_Log(RTMP_LOGDEBUG, "SWFSize  : %lu", r->Link.SWFSize);
+      RTMP_Log(RTMP_LOGDEBUG, "SWFSize  : %lu", (unsigned long)r->Link.SWFSize);
     }
   else
     {
@@ -966,7 +967,8 @@
       }
     else
       {
-        RTMP_Log(RTMP_LOGERROR, "%s, SOCKS returned error code %d", packet[1]);
+        RTMP_Log(RTMP_LOGERROR, "%s, SOCKS returned error code %d",
+                 __FUNCTION__, (int)packet[1]);
         return FALSE;
       }
   }
@@ -1154,14 +1156,14 @@
       /* flex stream send */
       RTMP_Log(RTMP_LOGDEBUG,
 	  "%s, flex stream send, size %lu bytes, not supported, ignoring",
-	  __FUNCTION__, packet->m_nBodySize);
+	  __FUNCTION__, (unsigned long)packet->m_nBodySize);
       break;
 
     case RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT:
       /* flex shared object */
       RTMP_Log(RTMP_LOGDEBUG,
 	  "%s, flex shared object, size %lu bytes, not supported, ignoring",
-	  __FUNCTION__, packet->m_nBodySize);
+	  __FUNCTION__, (unsigned long)packet->m_nBodySize);
       break;
 
     case RTMP_PACKET_TYPE_FLEX_MESSAGE:
@@ -1169,19 +1171,21 @@
       {
 	RTMP_Log(RTMP_LOGDEBUG,
 	    "%s, flex message, size %lu bytes, not fully supported",
-	    __FUNCTION__, packet->m_nBodySize);
+	    __FUNCTION__, (unsigned long)packet->m_nBodySize);
 	/*RTMP_LogHex(packet.m_body, packet.m_nBodySize); */
 
 	/* some DEBUG code */
 #if 0
-	   RTMP_LIB_AMFObject obj;
-	   int nRes = obj.Decode(packet.m_body+1, packet.m_nBodySize-1);
-	   if(nRes < 0) {
-	   RTMP_Log(RTMP_LOGERROR, "%s, error decoding AMF3 packet", __FUNCTION__);
-	   /*return; */
-	   }
+       RTMP_LIB_AMFObject obj;
+       int nRes = obj.Decode(packet.m_body + 1, packet.m_nBodySize - 1);
+       if (nRes < 0)
+         {
+           RTMP_Log(RTMP_LOGERROR, "%s, error decoding AMF3 packet",
+                    __FUNCTION__);
+           /*return; */
+         }
 
-	   obj.Dump();
+       obj.Dump();
 #endif
 
 	if (HandleInvoke(r, packet->m_body + 1, packet->m_nBodySize - 1) == 1)
@@ -1191,7 +1195,7 @@
     case RTMP_PACKET_TYPE_INFO:
       /* metadata (notify) */
       RTMP_Log(RTMP_LOGDEBUG, "%s, received: notify %lu bytes", __FUNCTION__,
-	  packet->m_nBodySize);
+	  (unsigned long)packet->m_nBodySize);
       if (HandleMetadata(r, packet->m_body, packet->m_nBodySize))
 	bHasMediaPacket = 1;
       break;
@@ -1204,7 +1208,7 @@
     case RTMP_PACKET_TYPE_INVOKE:
       /* invoke */
       RTMP_Log(RTMP_LOGDEBUG, "%s, received: invoke %lu bytes", __FUNCTION__,
-	  packet->m_nBodySize);
+	  (unsigned long)packet->m_nBodySize);
       /*RTMP_LogHex(packet.m_body, packet.m_nBodySize); */
 
       if (HandleInvoke(r, packet->m_body, packet->m_nBodySize) == 1)
@@ -3011,7 +3015,7 @@
   if (ReadN(r, packet->m_body + packet->m_nBytesRead, nChunk) != nChunk)
     {
       RTMP_Log(RTMP_LOGERROR, "%s, failed to read RTMP packet body. len: %lu",
-	  __FUNCTION__, packet->m_nBodySize);
+	  __FUNCTION__, (unsigned long)packet->m_nBodySize);
       return FALSE;
     }
 
@@ -4144,7 +4148,7 @@
 		    {
 		      RTMP_Log(RTMP_LOGERROR,
 			  "Wrong data size (%lu), stream corrupted, aborting!",
-			  dataSize);
+			  (unsigned long)dataSize);
 		      ret = RTMP_READ_ERROR;
 		      break;
 		    }
Index: rtmpdump.c
--- rtmpdump.c
+++ rtmpdump.c
@@ -746,7 +746,7 @@
 	    ("--resume|-e             Resume a partial RTMP download\n");
 	  RTMP_LogPrintf
 	    ("--timeout|-m num        Timeout connection num seconds (default: %lu)\n",
-	     DEF_TIMEOUT);
+	     (unsigned long)DEF_TIMEOUT);
 	  RTMP_LogPrintf
 	    ("--start|-A num          Start at num seconds into stream (not valid when using --live)\n");
 	  RTMP_LogPrintf
@@ -757,7 +757,7 @@
 	    ("--hashes|-#             Display progress with hashes, not with the byte counter\n");
 	  RTMP_LogPrintf
 	    ("--buffer|-b             Buffer time in milliseconds (default: %lu)\n",
-	     DEF_BUFTIME);
+	     (unsigned long)DEF_BUFTIME);
 	  RTMP_LogPrintf
 	    ("--skip|-k num           Skip num keyframes when looking for last keyframe to resume from. Useful if resume fails (default: %d)\n\n",
 	     DEF_SKIPFRM);
Index: rtmpgw.c
--- rtmpgw.c
+++ rtmpgw.c
@@ -572,7 +572,8 @@
   rtmp.Link.token = req.token;
   rtmp.m_read.timestamp = dSeek;
 
-  RTMP_LogPrintf("Connecting ... port: %d, app: %s\n", req.rtmpport, req.app);
+  RTMP_LogPrintf("Connecting ... port: %d, app: %.*s\n", req.rtmpport,
+    req.app.av_len, req.app.av_val);
   if (!RTMP_Connect(&rtmp, NULL))
     {
       RTMP_LogPrintf("%s, failed to connect!\n", __FUNCTION__);
@@ -754,8 +755,11 @@
 	}
 
       if (closesocket(server->socket))
-	RTMP_Log(RTMP_LOGERROR, "%s: Failed to close listening socket, error %d",
-	    GetSockError());
+        {
+          RTMP_Log(RTMP_LOGERROR,
+                   "%s: Failed to close listening socket, error %d",
+                   __FUNCTION__, GetSockError());
+        }
 
       server->state = STREAMING_STOPPED;
     }
@@ -766,7 +770,7 @@
 sigIntHandler(int sig)
 {
   RTMP_ctrlC = TRUE;
-  RTMP_LogPrintf("Caught signal: %d, cleaning up, just a second...\n",
+  RTMP_LogPrintf("Caught signal: %s (%d), cleaning up, just a second...\n",
                  strsignal(sig), sig);
   if (httpServer)
     stopStreaming(httpServer);
@@ -1128,7 +1132,7 @@
 	    ("--token|-T key          Key for SecureToken response\n");
 	  RTMP_LogPrintf
 	    ("--buffer|-b             Buffer time in milliseconds (default: %lu)\n\n",
-	     defaultRTMPRequest.bufferTime);
+	     (unsigned long)defaultRTMPRequest.bufferTime);
 
 	  RTMP_LogPrintf
 	    ("--device|-D             Streaming device ip address (default: %s)\n",
Index: rtmpsrv.c
--- rtmpsrv.c
+++ rtmpsrv.c
@@ -740,8 +740,9 @@
 {
   int ret = 0;
 
-  RTMP_Log(RTMP_LOGDEBUG, "%s, received packet type %02X, size %lu bytes", __FUNCTION__,
-    packet->m_packetType, packet->m_nBodySize);
+  RTMP_Log(RTMP_LOGDEBUG, "%s, received packet type %02X, size %lu bytes",
+           __FUNCTION__, packet->m_packetType,
+           (unsigned long)packet->m_nBodySize);
 
   switch (packet->m_packetType)
     {
@@ -806,7 +807,7 @@
       {
 	RTMP_Log(RTMP_LOGDEBUG,
                  "%s, flex message, size %lu bytes, not fully supported",
-	         __FUNCTION__, packet->m_nBodySize);
+	         __FUNCTION__, (unsigned long)packet->m_nBodySize);
 #if 0
 	RTMP_LogHex(packet.m_body, packet.m_nBodySize);
 #endif
@@ -840,7 +841,7 @@
     case RTMP_PACKET_TYPE_INVOKE:
       /* invoke */
       RTMP_Log(RTMP_LOGDEBUG, "%s, received: invoke %lu bytes", __FUNCTION__,
-	       packet->m_nBodySize);
+	       (unsigned long)packet->m_nBodySize);
 #if 0
       RTMP_LogHex(packet.m_body, packet.m_nBodySize);
 #endif
@@ -1049,8 +1050,11 @@
 	}
 
       if (closesocket(server->socket))
-	RTMP_Log(RTMP_LOGERROR, "%s: Failed to close listening socket, error %d",
-	    GetSockError());
+        {
+          RTMP_Log(RTMP_LOGERROR,
+                   "%s: Failed to close listening socket, error %d",
+                   __FUNCTION__, GetSockError());
+        }
 
       server->state = STREAMING_STOPPED;
     }
@@ -1061,7 +1065,7 @@
 sigIntHandler(int sig)
 {
   RTMP_ctrlC = TRUE;
-  RTMP_LogPrintf("Caught signal: %d, cleaning up, just a second...\n",
+  RTMP_LogPrintf("Caught signal: %s (%d), cleaning up, just a second...\n",
                  strsignal(sig), sig);
   if (rtmpServer)
     stopStreaming(rtmpServer);
Index: rtmpsuck.c
--- rtmpsuck.c
+++ rtmpsuck.c
@@ -457,8 +457,9 @@
 {
   int ret = 0;
 
-  RTMP_Log(RTMP_LOGDEBUG, "%s, %s sent packet type %02X, size %lu bytes", __FUNCTION__,
-    cst[which], packet->m_packetType, packet->m_nBodySize);
+  RTMP_Log(RTMP_LOGDEBUG, "%s, %s sent packet type %02X, size %lu bytes",
+           __FUNCTION__, cst[which], packet->m_packetType,
+           (unsigned long)packet->m_nBodySize);
 
   switch (packet->m_packetType)
     {
@@ -669,7 +670,7 @@
 		    {
 		      RTMP_Log(RTMP_LOGERROR,
 			  "Wrong data size (%lu), stream corrupted, aborting!",
-			  dataSize);
+			  (unsigned long)dataSize);
 		      ret = -2;
 		      break;
 		    }
@@ -1139,8 +1140,11 @@
 	}
 
       if (fd && closesocket(fd))
-	RTMP_Log(RTMP_LOGERROR, "%s: Failed to close listening socket, error %d",
-	    GetSockError());
+        {
+          RTMP_Log(RTMP_LOGERROR,
+                   "%s: Failed to close listening socket, error %d",
+                   __FUNCTION__, GetSockError());
+        }
 
       server->state = STREAMING_STOPPED;
     }
@@ -1151,7 +1155,7 @@
 sigIntHandler(int sig)
 {
   RTMP_ctrlC = TRUE;
-  RTMP_LogPrintf("Caught signal: %d, cleaning up, just a second...\n",
+  RTMP_LogPrintf("Caught signal: %s (%d), cleaning up, just a second...\n",
                  strsignal(sig), sig);
   if (rtmpServer)
     stopStreaming(rtmpServer);


More information about the rtmpdump mailing list