[rtmpdump] patch: gcc -Wextra

Peter Miller pmiller at opensource.org.au
Fri Apr 8 17:34:07 CEST 2011


This patch adds the gcc -Wextra flag, and fixes all the warnings it
produces.


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

"A program that produces incorrect results twice as fast is infinitely
slower." -- John Osterhout
-------------- next part --------------
MIME-Version: 1.0
Content-Type: application/aegis-patch
Subject: rtmpdump.2.3 - gcc -Wextra
Content-Name: rtmpdump.2.3.C024.patch
Content-Disposition: attachment; filename=rtmpdump.2.3.C024.patch
X-Aegis-Project-Name: rtmpdump.2.3
X-Aegis-Change-Number: 24

#	
#	This change set adds the gcc -Wextra flag, and fixes all the warnings
#	it produces.
#	
# Aegis-Change-Set-Begin
# QlpoMzFBWSZTWfx/gu8AAbVfgAAQUAf/6gACBIq/79/qQALcsDYEAaICZKe0nkno0Jk01MQA
# yEU8TQGmJSG1CNGAAAMZDIaDQaNAGgAaGCKIp6CT0m0BE9J6nqaPFDQM2FeG0A/4MCs0UkGq
# j6HOOak9pIlGAYB9g9r7pt0tWsA2pINO8tNSluF8eXnX5QcvtglL49jQYQYHoAB5ALu7Svna
# /bZTFwltJ9y0Law3HI72sHiXDBFwC82FRg6IBOA7/Pv6/Vj4lxI9tuANfloT928+PLU6nbfk
# bCIt1IO/B55tw57vew53aKE74CxDeZKxsEgSGumR1EExHMEey5Q5HKKVpFQ1iAMV0RWOYy2Y
# VqbyuMsJk2TadVV9JoXOWWpWGqb5pqIPG0pLALIKYit3ZTTEwieJJMMObWVypooleuiWpuYm
# YKCTGyaFbgQRgVBKDC0BxFZwdxJM0zRTW2gG78yTEz9PcGokwUB5CLPeLjuFuPnN8eqAC6/2
# Es5qO5tjc54PeyrGiUGFLSmLZAE1V02y2ALXf4F7TALFCguKKQ5MjalsFTB8dGUbNev2ivE8
# Tt/ABWNO4AikGIcLUa2mD0hBcIWx5jdppiAUPC+gonmIgFeQLWuo8nxlxDhYzo2jH3TQ4Pwp
# hkLV+AC4SR218AEeHIAtjPqHe1e6ZHGWc5TpoRgFOABbVaZVcFVWayG1/uPJZDJDrw1RNToX
# kMsyf33xc3fCd7FoZnV20pklw9QC6nIHp9zpXrUGl0dex6d90cz3r1X69kY8geIvrovyzkXC
# 871zw1S4RTcLtXbXMmQY2zgDlnCF8FncrqzBvLERTQT0BpqKKxmDSql+mRsYltIPD8V5bTLV
# rM9C7AudN3hjwpkDBGnxrN1AdWVwTO+GmPAuDHCl++MS7AzB3A9TXZx8crOSNN4PgDbbKNte
# jZbHHQ+MHEHAB+BdyRThQkPx/gu8
# Aegis-Change-Set-End
#
Index: Makefile
--- Makefile
+++ Makefile
@@ -21,7 +21,7 @@
 
 DEF=-DRTMPDUMP_VERSION=\"$(VERSION)\" $(CRYPTO_DEF) $(XDEF)
 OPT=-O2
-CFLAGS=-Wall -Werror $(XCFLAGS) $(INC) $(DEF) $(OPT)
+CFLAGS=-Wall -Wextra -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 -Werror $(XCFLAGS) $(INC) $(DEF) $(OPT) $(SO_DEF)
+CFLAGS=-Wall -Wextra -Werror $(XCFLAGS) $(INC) $(DEF) $(OPT) $(SO_DEF)
 LDFLAGS=$(XLDFLAGS)
 
 
Index: librtmp/amf.c
--- librtmp/amf.c
+++ librtmp/amf.c
@@ -32,7 +32,7 @@
 #include "log.h"
 #include "bytes.h"
 
-static const AMFObjectProperty AMFProp_Invalid = { {0, 0}, AMF_INVALID };
+static const AMFObjectProperty AMFProp_Invalid = { {0, 0}, AMF_INVALID, {0}, 0 };
 static const AVal AV_empty = { 0, 0 };
 
 /* Data is Big-Endian */
@@ -957,8 +957,7 @@
     {
       int32_t classRef = (ref >> 1);
 
-      AMF3ClassDef cd = { {0, 0}
-      };
+      AMF3ClassDef cd = { {0, 0}, 0, 0, 0, 0 };
       AMFObjectProperty prop;
 
       if ((classRef & 0x1) == 0)
Index: librtmp/handshake.h
--- librtmp/handshake.h
+++ librtmp/handshake.h
@@ -176,6 +176,7 @@
   uint8_t *ptr = handshake + 772;
   unsigned int res;
 
+  (void)len;
   offset += (*ptr);
   ptr++;
   offset += (*ptr);
Index: librtmp/hashswf.c
--- librtmp/hashswf.c
+++ librtmp/hashswf.c
@@ -87,7 +87,8 @@
   int len_known;
   HTTPResult ret = HTTPRES_OK;
   struct sockaddr_in sa;
-  RTMPSockBuf sb = {0};
+  static RTMPSockBuf sb_zero;
+  RTMPSockBuf sb = sb_zero;
 
   http->status = -1;
 
@@ -458,10 +459,12 @@
   time_t ctim = -1, cnow;
   int i, got = 0, ret = 0;
   unsigned int hlen;
-  struct info in = { 0 };
-  struct HTTP_ctx http = { 0 };
+  static struct info in_zero;
+  struct info in = in_zero;
+  struct HTTP_ctx http = { 0, 0, 0, 0 };
   HTTPResult httpres;
-  z_stream zs = { 0 };
+  static z_stream zs_zero;
+  z_stream zs = zs_zero;
   AVal home, hpre;
 
   date[0] = '\0';
Index: librtmp/log.c
--- librtmp/log.c
+++ librtmp/log.c
@@ -38,183 +38,210 @@
 
 static FILE *fmsg;
 
-static RTMP_LogCallback rtmp_log_default, *cb = rtmp_log_default;
-
 static const char *levels[] = {
   "CRIT", "ERROR", "WARNING", "INFO",
   "DEBUG", "DEBUG2"
 };
 
-static void rtmp_log_default(int level, const char *format, va_list vl)
+static void
+rtmp_log_default(RTMP_LogLevel level, const char *format, va_list vl)
 {
-	char str[MAX_PRINT_LEN]="";
-
-	vsnprintf(str, MAX_PRINT_LEN-1, format, vl);
+  char str[MAX_PRINT_LEN] = "";
 
-	/* Filter out 'no-name' */
-	if ( RTMP_debuglevel<RTMP_LOGALL && strstr(str, "no-name" ) != NULL )
-		return;
+  vsnprintf(str, MAX_PRINT_LEN - 1, format, vl);
 
-	if ( !fmsg ) fmsg = stderr;
-
-	if ( level <= RTMP_debuglevel ) {
-		if (neednl) {
-			putc('\n', fmsg);
-			neednl = 0;
-		}
-		fprintf(fmsg, "%s: %s\n", levels[level], str);
+  /* Filter out 'no-name' */
+  if (RTMP_debuglevel < RTMP_LOGALL && strstr(str, "no-name") != NULL)
+    return;
+
+  if (!fmsg)
+    fmsg = stderr;
+
+  if (level <= RTMP_debuglevel)
+    {
+      if (neednl)
+	{
+	  putc('\n', fmsg);
+	  neednl = 0;
+	}
+      fprintf(fmsg, "%s: %s\n", levels[level], str);
 #ifdef _DEBUG
-		fflush(fmsg);
+      fflush(fmsg);
 #endif
-	}
+    }
 }
 
-void RTMP_LogSetOutput(FILE *file)
+static RTMP_LogCallback cb = rtmp_log_default;
+
+void
+RTMP_LogSetOutput(FILE * file)
 {
-	fmsg = file;
+  fmsg = file;
 }
 
-void RTMP_LogSetLevel(RTMP_LogLevel level)
+void
+RTMP_LogSetLevel(RTMP_LogLevel level)
 {
-	RTMP_debuglevel = level;
+  RTMP_debuglevel = level;
 }
 
-void RTMP_LogSetCallback(RTMP_LogCallback *cbp)
+void
+RTMP_LogSetCallback(RTMP_LogCallback cbp)
 {
-	cb = cbp;
+  cb = cbp;
 }
 
-RTMP_LogLevel RTMP_LogGetLevel()
+RTMP_LogLevel
+RTMP_LogGetLevel()
 {
-	return RTMP_debuglevel;
+  return RTMP_debuglevel;
 }
 
-void RTMP_Log(int level, const char *format, ...)
+void
+RTMP_Log(RTMP_LogLevel level, const char *format, ...)
 {
-	va_list args;
-	va_start(args, format);
-	cb(level, format, args);
-	va_end(args);
+  va_list args;
+  va_start(args, format);
+  cb(level, format, args);
+  va_end(args);
 }
 
 static const char hexdig[] = "0123456789abcdef";
 
-void RTMP_LogHex(int level, const uint8_t *data, unsigned long len)
+void
+RTMP_LogHex(RTMP_LogLevel level, const uint8_t *data, unsigned long len)
 {
-	unsigned long i;
-	char line[50], *ptr;
-
-	if ( level > RTMP_debuglevel )
-		return;
+  unsigned long i;
+  char line[50], *ptr;
 
-	ptr = line;
+  if (level > RTMP_debuglevel)
+    return;
 
-	for(i=0; i<len; i++) {
-		*ptr++ = hexdig[0x0f & (data[i] >> 4)];
-		*ptr++ = hexdig[0x0f & data[i]];
-		if ((i & 0x0f) == 0x0f) {
-			*ptr = '\0';
-			ptr = line;
-			RTMP_Log(level, "%s", line);
-		} else {
-			*ptr++ = ' ';
-		}
+  ptr = line;
+
+  for (i = 0; i < len; i++)
+    {
+      *ptr++ = hexdig[0x0f & (data[i] >> 4)];
+      *ptr++ = hexdig[0x0f & data[i]];
+      if ((i & 0x0f) == 0x0f)
+	{
+	  *ptr = '\0';
+	  ptr = line;
+	  RTMP_Log(level, "%s", line);
 	}
-	if (i & 0x0f) {
-		*ptr = '\0';
-		RTMP_Log(level, "%s", line);
+      else
+	{
+	  *ptr++ = ' ';
 	}
+    }
+  if (i & 0x0f)
+    {
+      *ptr = '\0';
+      RTMP_Log(level, "%s", line);
+    }
 }
 
-void RTMP_LogHexString(int level, const uint8_t *data, unsigned long len)
+void
+RTMP_LogHexString(RTMP_LogLevel level, const uint8_t *data, unsigned long len)
 {
 #define BP_OFFSET 9
 #define BP_GRAPH 60
 #define BP_LEN	80
-	char	line[BP_LEN];
-	unsigned long i;
-
-	if ( !data || level > RTMP_debuglevel )
-		return;
-
-	/* in case len is zero */
-	line[0] = '\0';
-
-	for ( i = 0 ; i < len ; i++ ) {
-		int n = i % 16;
-		unsigned off;
-
-		if( !n ) {
-			if( i ) RTMP_Log( level, "%s", line );
-			memset( line, ' ', sizeof(line)-2 );
-			line[sizeof(line)-2] = '\0';
-
-			off = i % 0x0ffffU;
-
-			line[2] = hexdig[0x0f & (off >> 12)];
-			line[3] = hexdig[0x0f & (off >>  8)];
-			line[4] = hexdig[0x0f & (off >>  4)];
-			line[5] = hexdig[0x0f & off];
-			line[6] = ':';
-		}
+  char line[BP_LEN];
+  unsigned long i;
 
-		off = BP_OFFSET + n*3 + ((n >= 8)?1:0);
-		line[off] = hexdig[0x0f & ( data[i] >> 4 )];
-		line[off+1] = hexdig[0x0f & data[i]];
+  if (!data || level > RTMP_debuglevel)
+    return;
 
-		off = BP_GRAPH + n + ((n >= 8)?1:0);
+  /* in case len is zero */
+  line[0] = '\0';
 
-		if ( isprint( data[i] )) {
-			line[BP_GRAPH + n] = data[i];
-		} else {
-			line[BP_GRAPH + n] = '.';
-		}
+  for (i = 0; i < len; i++)
+    {
+      int n = i % 16;
+      unsigned off;
+
+      if (!n)
+	{
+	  if (i)
+	    RTMP_Log(level, "%s", line);
+	  memset(line, ' ', sizeof(line) - 2);
+	  line[sizeof(line) - 2] = '\0';
+
+	  off = i % 0x0ffffU;
+
+	  line[2] = hexdig[0x0f & (off >> 12)];
+	  line[3] = hexdig[0x0f & (off >> 8)];
+	  line[4] = hexdig[0x0f & (off >> 4)];
+	  line[5] = hexdig[0x0f & off];
+	  line[6] = ':';
 	}
 
-	RTMP_Log( level, "%s", line );
-}
-
-/* These should only be used by apps, never by the library itself */
-void RTMP_LogPrintf(const char *format, ...)
-{
-	char str[MAX_PRINT_LEN]="";
-	int len;
-	va_list args;
-	va_start(args, format);
-	len = vsnprintf(str, MAX_PRINT_LEN-1, format, args);
-	va_end(args);
-
-	if ( RTMP_debuglevel==RTMP_LOGCRIT )
-		return;
-
-	if ( !fmsg ) fmsg = stderr;
-
-	if (neednl) {
-		putc('\n', fmsg);
-		neednl = 0;
+      off = BP_OFFSET + n * 3 + ((n >= 8) ? 1 : 0);
+      line[off] = hexdig[0x0f & (data[i] >> 4)];
+      line[off + 1] = hexdig[0x0f & data[i]];
+
+      off = BP_GRAPH + n + ((n >= 8) ? 1 : 0);
+
+      if (isprint(data[i]))
+	{
+	  line[BP_GRAPH + n] = data[i];
+	}
+      else
+	{
+	  line[BP_GRAPH + n] = '.';
 	}
+    }
 
-    if (len > MAX_PRINT_LEN-1)
-          len = MAX_PRINT_LEN-1;
-	fprintf(fmsg, "%s", str);
-    if (str[len-1] == '\n')
-		fflush(fmsg);
+  RTMP_Log(level, "%s", line);
 }
 
-void RTMP_LogStatus(const char *format, ...)
+/* These should only be used by apps, never by the library itself */
+void
+RTMP_LogPrintf(const char *format, ...)
 {
-	char str[MAX_PRINT_LEN]="";
-	va_list args;
-	va_start(args, format);
-	vsnprintf(str, MAX_PRINT_LEN-1, format, args);
-	va_end(args);
-
-	if ( RTMP_debuglevel==RTMP_LOGCRIT )
-		return;
-
-	if ( !fmsg ) fmsg = stderr;
-
-	fprintf(fmsg, "%s", str);
-	fflush(fmsg);
-	neednl = 1;
+  char str[MAX_PRINT_LEN] = "";
+  int len;
+  va_list args;
+  va_start(args, format);
+  len = vsnprintf(str, MAX_PRINT_LEN - 1, format, args);
+  va_end(args);
+
+  if (RTMP_debuglevel == RTMP_LOGCRIT)
+    return;
+
+  if (!fmsg)
+    fmsg = stderr;
+
+  if (neednl)
+    {
+      putc('\n', fmsg);
+      neednl = 0;
+    }
+
+  if (len > MAX_PRINT_LEN - 1)
+    len = MAX_PRINT_LEN - 1;
+  fprintf(fmsg, "%s", str);
+  if (str[len - 1] == '\n')
+    fflush(fmsg);
+}
+
+void
+RTMP_LogStatus(const char *format, ...)
+{
+  char str[MAX_PRINT_LEN] = "";
+  va_list args;
+  va_start(args, format);
+  vsnprintf(str, MAX_PRINT_LEN - 1, format, args);
+  va_end(args);
+
+  if (RTMP_debuglevel == RTMP_LOGCRIT)
+    return;
+
+  if (!fmsg)
+    fmsg = stderr;
+
+  fprintf(fmsg, "%s", str);
+  fflush(fmsg);
+  neednl = 1;
 }
Index: librtmp/log.h
--- librtmp/log.h
+++ librtmp/log.h
@@ -51,14 +51,16 @@
 
 extern RTMP_LogLevel RTMP_debuglevel;
 
-typedef void (RTMP_LogCallback)(int level, const char *fmt, va_list);
-void RTMP_LogSetCallback(RTMP_LogCallback *cb);
+typedef void (*RTMP_LogCallback)(RTMP_LogLevel level, const char *fmt, va_list);
+void RTMP_LogSetCallback(RTMP_LogCallback cb);
 void RTMP_LogSetOutput(FILE *file);
 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_Log(RTMP_LogLevel level, const char *format, ...)
+    RTMP_ATTR_PRINTF(2, 3);
+void RTMP_LogHex(RTMP_LogLevel level, const uint8_t *data, unsigned long len);
+void RTMP_LogHexString(RTMP_LogLevel level, const uint8_t *data,
+    unsigned long len);
 void RTMP_LogSetLevel(RTMP_LogLevel lvl);
 RTMP_LogLevel RTMP_LogGetLevel(void);
 
Index: librtmp/rtmp.c
--- librtmp/rtmp.c
+++ librtmp/rtmp.c
@@ -111,7 +111,7 @@
 static void HandleClientBW(RTMP *r, const RTMPPacket *packet);
 
 static int ReadN(RTMP *r, char *buffer, int n);
-static int WriteN(RTMP *r, const char *buffer, int n);
+static int WriteN(RTMP *r, const char *buffer, size_t n);
 
 static void DecodeTEA(AVal *key, AVal *text);
 
@@ -492,7 +492,7 @@
   	"Buffer time in milliseconds" },
   { AVC("timeout"),   OFF(Link.timeout),       OPT_INT, 0,
   	"Session timeout in seconds" },
-  { {NULL,0}, 0, 0}
+  { {NULL, 0}, 0, 0, 0, 0 }
 };
 
 static const AVal truth[] = {
@@ -517,7 +517,8 @@
 static int
 parseAMF(AMFObject *obj, AVal *av, int *depth)
 {
-  AMFObjectProperty prop = {{0,0}};
+  static AMFObjectProperty prop_zero;
+  AMFObjectProperty prop = prop_zero;
   int i;
   char *p, *arg = av->av_val;
 
@@ -977,7 +978,8 @@
 int
 RTMP_ConnectStream(RTMP *r, int seekTime)
 {
-  RTMPPacket packet = { 0 };
+  static RTMPPacket packet_zero;
+  RTMPPacket packet = packet_zero;
 
   /* seekTime was already set by SetupStream / SetupURL.
    * This is only needed by ReconnectStream.
@@ -1367,7 +1369,7 @@
 }
 
 static int
-WriteN(RTMP *r, const char *buffer, int n)
+WriteN(RTMP *r, const char *buffer, size_t n)
 {
   const char *ptr = buffer;
 #ifdef CRYPTO
@@ -1398,8 +1400,8 @@
       if (nBytes < 0)
 	{
 	  int sockerr = GetSockError();
-	  RTMP_Log(RTMP_LOGERROR, "%s, RTMP send error %d (%d bytes)", __FUNCTION__,
-	      sockerr, n);
+	  RTMP_Log(RTMP_LOGERROR, "%s, RTMP send error %d (%lu bytes)",
+                   __FUNCTION__, sockerr, (unsigned long)n);
 
 	  if (sockerr == EINTR && !RTMP_ctrlC)
 	    continue;
@@ -2324,7 +2326,8 @@
 
   if (AVMATCH(&method, &av__result))
     {
-      AVal methodInvoked = {0};
+      static AVal methodInvoked_zero;
+      AVal methodInvoked = methodInvoked_zero;
       int i;
 
       for (i=0; i<r->m_numCalls; i++) {
@@ -2693,11 +2696,15 @@
 static void
 HandleAudio(RTMP *r, const RTMPPacket *packet)
 {
+    (void)r;
+    (void)packet;
 }
 
 static void
 HandleVideo(RTMP *r, const RTMPPacket *packet)
 {
+    (void)r;
+    (void)packet;
 }
 
 static void
@@ -3755,8 +3762,10 @@
 Read_1_Packet(RTMP *r, char *buf, unsigned int buflen)
 {
   uint32_t prevTagSize = 0;
-  int rtnGetNextMediaPacket = 0, ret = RTMP_READ_EOF;
-  RTMPPacket packet = { 0 };
+  int rtnGetNextMediaPacket = 0;
+  int ret = RTMP_READ_EOF;
+  static RTMPPacket packet_zero;
+  RTMPPacket packet = packet_zero;
   int recopy = FALSE;
   unsigned int size;
   char *ptr, *pend;
@@ -4212,9 +4221,9 @@
   if (rtnGetNextMediaPacket)
     RTMPPacket_Free(&packet);
 
-  if (recopy)
+  if (recopy && ret > 0)
     {
-      len = ret > buflen ? buflen : ret;
+      len = (unsigned)ret > buflen ? buflen : (unsigned)ret;
       memcpy(buf, r->m_read.buf, len);
       r->m_read.bufpos = r->m_read.buf + len;
       r->m_read.buflen = ret - len;
Index: rtmpdump.c
--- rtmpdump.c
+++ rtmpdump.c
@@ -347,7 +347,7 @@
 	  return RD_FAILED;
 	}
 
-      if (prevTagSize < 0 || prevTagSize > size - 4 - 13)
+      if ((int32_t)prevTagSize < 0 || prevTagSize > size - 4 - 13)
 	{
 	  RTMP_Log(RTMP_LOGERROR,
 	      "Last tag size must be greater/equal zero (prevTagSize=%d) and smaller then filesize, corrupt file!",
@@ -416,7 +416,7 @@
     }
 #endif
 
-  if (*dSeek < 0)
+  if ((int32_t)*dSeek < 0)
     {
       RTMP_Log(RTMP_LOGERROR,
 	  "Last keyframe timestamp is negative, aborting, your file is corrupt!");
@@ -490,6 +490,7 @@
   unsigned long lastPercent = 0;
   int status;
 
+  (void)bStdoutMode;
   rtmp->m_read.timestamp = dSeek;
 
   *percent = 0.0;
@@ -813,7 +814,8 @@
   long int timeout = DEF_TIMEOUT;     /* timeout connection after 120 seconds */
   uint32_t dStartOffset = 0;	/* seek position in non-live mode */
   uint32_t dStopOffset = 0;
-  RTMP rtmp = { 0 };
+  static const RTMP rtmp_zero;
+  RTMP rtmp = rtmp_zero;
 
   AVal swfUrl = { 0, 0 };
   AVal tcUrl = { 0, 0 };
Index: rtmpgw.c
--- rtmpgw.c
+++ rtmpgw.c
@@ -115,7 +115,8 @@
 int
 parseAMF(AMFObject *obj, const char *arg, int *depth)
 {
-  AMFObjectProperty prop = {{0,0}};
+  static const AMFObjectProperty prop_zero;
+  AMFObjectProperty prop = prop_zero;
   int i;
   char *p;
 
@@ -265,6 +266,7 @@
 controlServerThread(void *unused)
 {
   char ich;
+  (void)unused;
   while (1)
     {
       ich = getchar();
@@ -341,7 +343,8 @@
 
   server->state = STREAMING_IN_PROGRESS;
 
-  RTMP rtmp = { 0 };
+  static const RTMP rtmp_zero;
+  RTMP rtmp = rtmp_zero;
   uint32_t dSeek = 0;		/* can be used to start from a later point in the stream */
 
   /* reset RTMP options to defaults specified upon invokation of streams */
Index: rtmpsrv.c
--- rtmpsrv.c
+++ rtmpsrv.c
@@ -342,7 +342,8 @@
     }
 #else
   /* reap any dead children */
-  while (waitpid(-1, NULL, WNOHANG) > 0);
+  while (waitpid(-1, NULL, WNOHANG) > 0)
+    ;
 
   if (fork() == 0) {
     char **argv = malloc((argc+1) * sizeof(char *));
@@ -357,6 +358,7 @@
       _exit(i);
   }
 #endif
+  (void)cmd;
 }
 
 static int
@@ -581,7 +583,8 @@
       AVal *argv, av;
       int len, argc;
       uint32_t now;
-      RTMPPacket pc = {0};
+      static const RTMPPacket pc_zero;
+      RTMPPacket pc = pc_zero;
       AMFProp_GetString(AMF_GetProp(&obj, NULL, 3), &r->Link.playpath);
       /*
       r->Link.seekTime = AMFProp_GetNumber(AMF_GetProp(&obj, NULL, 4));
@@ -867,6 +870,7 @@
 controlServerThread(void *unused)
 {
   char ich;
+  (void)unused;
   while (1)
     {
       ich = getchar();
@@ -892,8 +896,10 @@
 {
   server->state = STREAMING_IN_PROGRESS;
 
-  RTMP rtmp = { 0 };		/* our session with the real client */
-  RTMPPacket packet = { 0 };
+  static const RTMP rtmp_zero;
+  RTMP rtmp = rtmp_zero;		/* our session with the real client */
+  static const RTMPPacket packet_zero;
+  RTMPPacket packet = packet_zero;
 
   /* timeout for http requests */
   fd_set fds;
Index: rtmpsuck.c
--- rtmpsuck.c
+++ rtmpsuck.c
@@ -559,8 +559,11 @@
             RTMPPacket *packet)
 {
   uint32_t prevTagSize = 0;
-  int ret = -1, len = *plen;
+  int ret = -1;
+  int len = *plen;
 
+  if (len <= 0)
+    return 0;
   while (1)
     {
       char *packetBody = packet->m_body;
@@ -603,7 +606,7 @@
 	  || packet->m_packetType == RTMP_PACKET_TYPE_INFO) ? 11 : 0)
         + (packet->m_packetType != 0x16 ? 4 : 0);
 
-      if (size + 4 > len)
+      if (size + 4 > (unsigned)len)
 	{
           /* The extra 4 is for the case of an FLV stream without a last
            * prevTagSize (we need extra 4 bytes to append it).  */
@@ -725,7 +728,7 @@
       break;
     }
 
-  if (len > *plen)
+  if ((unsigned)len > *plen)
     *plen = len;
 
   return ret;			/* no more media packets */
@@ -735,6 +738,7 @@
 controlServerThread(void *unused)
 {
   char ich;
+  (void)unused;
   while (1)
     {
       ich = getchar();
@@ -757,8 +761,11 @@
 doServe(void *arg)	/* server socket and state (our listening socket) */
 {
   STREAMING_SERVER *server = arg;
-  RTMPPacket pc = { 0 }, ps = { 0 };
-  RTMPChunk rk = { 0 };
+  static const RTMPPacket packet_zero;
+  RTMPPacket pc = packet_zero;
+  RTMPPacket ps = packet_zero;
+  static const RTMPChunk rk_zero;
+  RTMPChunk rk = rk_zero;
   char *buf = NULL;
   unsigned int buflen = 131072;
   int paused = FALSE;
@@ -975,8 +982,12 @@
                        RTMP_ClientPacket(&server->rc, &pc))
                     {
                       int len = WriteStream(&buf, &buflen, &server->stamp, &pc);
-                      if (len > 0 && fwrite(buf, 1, len, server->f_cur->f_file) != len)
-                        goto cleanup;
+                      if (len > 0)
+                      {
+                        unsigned ulen = len;
+                        if (fwrite(buf, 1, ulen, server->f_cur->f_file) != ulen)
+                          goto cleanup;
+                      }
                     }
                   else if (pc.m_packetType == RTMP_PACKET_TYPE_FLEX_MESSAGE ||
                            pc.m_packetType == RTMP_PACKET_TYPE_INVOKE)


More information about the rtmpdump mailing list