From d4408b75db31f42e1423b6e706b91822fcb7c6a6 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Tue, 9 Sep 2014 16:24:20 +0000
Subject: Haiku patch


diff --git a/examples/Makefile.am b/examples/Makefile.am
index 87e5918..e3555d3 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -34,7 +34,7 @@ if HAVE_SYS_SOCKET_H
 decode_mpeg_SOURCES += connect.c connect.h
 endif
 decode_mpeg_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -DDVBPSI_DIST
-decode_mpeg_LDFLAGS = -L../src -ldvbpsi -lm
+decode_mpeg_LDFLAGS = -L../src -ldvbpsi -lnetwork
 
 decode_bat_SOURCES = decode_bat.c
 decode_bat_CPPFLAGS = -DDVBPSI_DIST
diff --git a/examples/decode_mpeg.c b/examples/decode_mpeg.c
index 3583f61..93143d6 100644
--- a/examples/decode_mpeg.c
+++ b/examples/decode_mpeg.c
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <string.h>
+#include <strings.h>
 #include <errno.h>
 #include <sys/types.h>
 #ifdef HAVE_SYS_TIME_H
diff --git a/examples/dvbinfo/Makefile.am b/examples/dvbinfo/Makefile.am
index b878676..0a2e76c 100644
--- a/examples/dvbinfo/Makefile.am
+++ b/examples/dvbinfo/Makefile.am
@@ -7,5 +7,5 @@ if HAVE_SYS_SOCKET_H
 dvbinfo_SOURCES += tcp.c tcp.h udp.c udp.h
 endif
 dvbinfo_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -DDVBPSI_DIST
-dvbinfo_LDFLAGS = -L../../src -ldvbpsi -pthread -lm
+dvbinfo_LDFLAGS = -L../../src -ldvbpsi -lnetwork -lbsd
 
-- 
1.8.3.4


From b58bc8958575425c65d185c49d5c844659250c75 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Fri, 12 Sep 2014 11:04:58 +0200
Subject: gcc2 fixes.


diff --git a/configure.ac b/configure.ac
index 2a97e5b..96ec091 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@ dnl store CFLAGS from user
 CFLAGS_save="${CFLAGS}"
 
 dnl add features to CFLAGS
-CFLAGS_dist="-Wall -Werror --std=gnu99 -D_GNU_SOURCE"
+CFLAGS_dist="-Wall --std=gnu9x -D_GNU_SOURCE"
 CFLAGS_dist="${CFLAGS_dist} -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Waggregate-return -Wmissing-prototypes -Wnested-externs -Wsign-compare"
 
 dnl check the operating system
diff --git a/examples/check_cc_pid.c b/examples/check_cc_pid.c
index cdf3181..935eb4b 100644
--- a/examples/check_cc_pid.c
+++ b/examples/check_cc_pid.c
@@ -33,35 +33,39 @@ static inline uint32_t ts_getpid(uint8_t *packet)
 
 int main(int argc, char *argv[])
 {
+	char* fname;
+	uint32_t tpid;
+	int file;
+    int32_t s = 188; /* COULD ALSO BE 192 */
+    uint8_t p[188] = { 0 };
+    int64_t n = 0;
+    size_t  len = 0;
+    uint32_t tcc = 0;
     if (argc != 3) {
         printf("Usage: check_cc_pid <filename> <pid>\n");
         return -1;
     }
 
     /* Get arguments */
-    char   *fname = argv[1];
-    uint32_t tpid = atoi(argv[2]); /* PID to track */
+    fname = argv[1];
+    tpid = atoi(argv[2]); /* PID to track */
     
-    int file = open(fname, O_RDONLY | O_NONBLOCK);
+    file = open(fname, O_RDONLY | O_NONBLOCK);
     if (file < 0) {
         perror(argv[1]);
         printf("error opening %s\n", argv[1]);
         return -1;
     }
 
-    int32_t s = 188; /* COULD ALSO BE 192 */
-    uint8_t p[188] = { 0 };
-    int64_t n = 0;
-    size_t  len = 0;
-    uint32_t tcc = 0;
     for (;;) {
+		uint32_t pid,cc;
 
         /* slow read */
         len = read(file, &p[0], s);
         if (len == 0)
             break;
-        uint32_t pid = ts_getpid(&p[0]);
-        uint32_t cc  = ts_getcc(&p[0]);
+        pid = ts_getpid(&p[0]);
+        cc  = ts_getcc(&p[0]);
         n++;
         tcc = cc;
         if (pid == tpid)
diff --git a/examples/decode_mpeg.c b/examples/decode_mpeg.c
index 93143d6..8ff5416 100644
--- a/examples/decode_mpeg.c
+++ b/examples/decode_mpeg.c
@@ -252,14 +252,14 @@ static void report_PCRPacketTiming( int i_cc, ts_pid_t *ts_pid,
 #endif
 {
     mtime_t i_delta = 0;
+    mtime_t time_current;
+    mtime_t tv_delta;
+    struct timeval tv;
 
     /* sequence number and program_id */
     printf( "%.2d %d ", i_cc, ts_pid->i_pid );
 
 #ifdef HAVE_GETTIMEOFDAY
-    mtime_t time_current;
-    mtime_t tv_delta;
-    struct timeval tv;
 
     /* arrival time of packet */
     gettimeofday( &tv, NULL );
diff --git a/examples/dump_pids.c b/examples/dump_pids.c
index e23598d..743e58c 100644
--- a/examples/dump_pids.c
+++ b/examples/dump_pids.c
@@ -34,24 +34,25 @@ static inline uint32_t ts_getpid(uint8_t *packet)
 int main(int argc, char *argv[])
 {
     int file = open(argv[1], O_RDONLY | O_NONBLOCK);
+    int32_t s = 188; /* COULD ALSO BE 192 */
+    uint8_t p[188] = { 0 };
+    int64_t n = 0;
+    size_t  len = 0;
     if (file < 0) {
         perror(argv[1]);
         printf("error opening %s\n", argv[1]);
         return -1;
     }
 
-    int32_t s = 188; /* COULD ALSO BE 192 */
-    uint8_t p[188] = { 0 };
-    int64_t n = 0;
-    size_t  len = 0;
     for (;;) {
+		uint32_t pid,cc;
 
         /* slow read */
         len = read(file, &p[0], s);
         if (len == 0)
             break;
-        uint32_t pid = ts_getpid(&p[0]);
-        uint32_t cc  = ts_getcc(&p[0]);
+        pid = ts_getpid(&p[0]);
+        cc  = ts_getcc(&p[0]);
         n++;
         printf("packet %"PRId64", pid %u (0x%x), cc %d\n", n, pid, pid, cc );
     }
diff --git a/examples/dvbinfo/buffer.c b/examples/dvbinfo/buffer.c
index 3d4b9c0..92acdff 100644
--- a/examples/dvbinfo/buffer.c
+++ b/examples/dvbinfo/buffer.c
@@ -86,11 +86,12 @@ fifo_t *fifo_new(void)
 
 void fifo_free(fifo_t *fifo)
 {
+	buffer_t* p;
     if (fifo == NULL)
         return;
 
     pthread_mutex_lock(&fifo->lock);
-    buffer_t *p = fifo->p_first;
+    p = fifo->p_first;
     if (p != NULL)
     {
         fifo->i_count = 0;
@@ -126,16 +127,18 @@ void fifo_wake(fifo_t *fifo)
 
 ssize_t fifo_count(fifo_t *fifo)
 {
+	ssize_t count;
     pthread_mutex_lock(&fifo->lock);
-    ssize_t count = fifo->i_count;
+    count = fifo->i_count;
     pthread_mutex_unlock(&fifo->lock);
     return count;
 }
 
 size_t fifo_size(fifo_t *fifo)
 {
+	size_t size;
     pthread_mutex_lock(&fifo->lock);
-    size_t size = fifo->i_size;
+    size = fifo->i_size;
     pthread_mutex_unlock(&fifo->lock);
     return size;
 }
diff --git a/examples/dvbinfo/dvbinfo.c b/examples/dvbinfo/dvbinfo.c
index 0db5b4a..5153f05 100644
--- a/examples/dvbinfo/dvbinfo.c
+++ b/examples/dvbinfo/dvbinfo.c
@@ -154,6 +154,7 @@ static void libdvbpsi_log(void *data, const int level, const char *format, ...)
     int err = 0;
     char *msg = NULL;
     va_list ap;
+    params_t *param = (params_t *)data;
 
     /* Get arguments and construct final message */
     va_start(ap, format);
@@ -169,7 +170,6 @@ static void libdvbpsi_log(void *data, const int level, const char *format, ...)
         return;
 
     /* Print message */
-    params_t *param = (params_t *)data;
     if (!param)
     {
         free(msg);
@@ -286,6 +286,7 @@ static void *dvbinfo_capture(void *data)
     while (capture->b_alive && !b_eof)
     {
         buffer_t *buffer;
+		size_t size;
 
         if (fifo_count(capture->empty) == 0)
             buffer = buffer_new(capture->size);
@@ -295,7 +296,7 @@ static void *dvbinfo_capture(void *data)
         if (buffer == NULL) /* out of memory */
             break;
 
-        ssize_t size = param->pf_read(param->fd_in, buffer->p_data, buffer->i_size);
+        size = param->pf_read(param->fd_in, buffer->p_data, buffer->i_size);
         if (size < 0) /* short read ? */
         {
             fifo_push(capture->empty, buffer);
@@ -353,6 +354,7 @@ static int dvbinfo_process(dvbinfo_capture_t *capture)
 
     char *psz_temp = NULL;
     mtime_t deadline = 0;
+    ts_stream_t *stream;
     if (param->b_summary)
     {
         if (asprintf(&psz_temp, "%s.part", param->summary.file) < 0)
@@ -364,7 +366,7 @@ static int dvbinfo_process(dvbinfo_capture_t *capture)
         deadline = mdate() + param->summary.period;
     }
 
-    ts_stream_t *stream = libdvbpsi_init(param->debug, &libdvbpsi_log, (void *)param);
+    stream = libdvbpsi_init(param->debug, &libdvbpsi_log, (void *)param);
     if (!stream)
         goto out;
 
@@ -407,11 +409,12 @@ static int dvbinfo_process(dvbinfo_capture_t *capture)
                 FILE *fd = fopen(psz_temp, "w+");
                 if (fd)
                 {
+					int ret;
                     libdvbpsi_summary(fd, stream, param->summary.mode);
                     fflush(fd);
                     fclose(fd);
                     unlink(param->summary.file);
-                    int ret = rename(psz_temp, param->summary.file);
+                    ret = rename(psz_temp, param->summary.file);
                     if (ret < 0)
                     {
                         libdvbpsi_log(param, DVBINFO_LOG_ERROR,
@@ -464,26 +467,8 @@ int main(int argc, char **pp_argv)
     dvbinfo_capture_t capture;
     params_t *param = NULL;
     char c;
-
-    printf("dvbinfo: Copyright (C) 2011-2012 M2X BV\n");
-    printf("License: LGPL v2.1\n");
-
-    if (argc == 1)
-        usage();
-
-    param = params_init();
-    if (param == NULL)
-    {
-        printf("dvbinfo: out of memory\n");
-        exit(EXIT_FAILURE);
-    }
-    capture.params = param;
-    capture.fifo = fifo_new();
-    capture.empty = fifo_new();
-    capture.b_fifo_full = false;
-    pthread_mutex_init(&capture.lock, NULL);
-    pthread_cond_init(&capture.fifo_full, NULL);
-
+    pthread_t handle;
+	int err;
     static const struct option long_options[] =
     {
         { "debug",     required_argument, NULL, 'd' },
@@ -506,6 +491,26 @@ int main(int argc, char **pp_argv)
 #endif
         { NULL, 0, NULL, 0 }
     };
+
+    printf("dvbinfo: Copyright (C) 2011-2012 M2X BV\n");
+    printf("License: LGPL v2.1\n");
+
+    if (argc == 1)
+        usage();
+
+    param = params_init();
+    if (param == NULL)
+    {
+        printf("dvbinfo: out of memory\n");
+        exit(EXIT_FAILURE);
+    }
+    capture.params = param;
+    capture.fifo = fifo_new();
+    capture.empty = fifo_new();
+    capture.b_fifo_full = false;
+    pthread_mutex_init(&capture.lock, NULL);
+    pthread_cond_init(&capture.fifo_full, NULL);
+
 #ifdef HAVE_SYS_SOCKET_H
     while ((c = getopt_long(argc, pp_argv, "a:d:f:i:j:ho:p:ms:tu", long_options, NULL)) != -1)
 #else
@@ -605,8 +610,8 @@ int main(int argc, char **pp_argv)
             {
                 if (optarg)
                 {
-                    ssize_t size = ARRAY_SIZE(psz_summary_mode);
-                    for (ssize_t i = 0; i < size; i++)
+                    ssize_t size = ARRAY_SIZE(psz_summary_mode), i;
+                    for (i = 0; i < size; i++)
                     {
                         printf("summary mode %s\n", psz_summary_mode[i]);
                         if (strncmp(optarg, psz_summary_mode[i], strlen(psz_summary_mode[i])) == 0)
@@ -716,7 +721,6 @@ int main(int argc, char **pp_argv)
 
     /* Capture thread */
     dvbinfo_open(param);
-    pthread_t handle;
     capture.b_alive = true;
     if (pthread_create(&handle, NULL, dvbinfo_capture, (void *)&capture) < 0)
     {
@@ -729,7 +733,7 @@ int main(int argc, char **pp_argv)
         params_free(param);
         exit(EXIT_FAILURE);
     }
-    int err = dvbinfo_process(&capture);
+    err = dvbinfo_process(&capture);
     capture.b_alive = false;     /* stop thread */
     if (pthread_join(handle, NULL) < 0)
         libdvbpsi_log(param, DVBINFO_LOG_ERROR, "error joining capture thread\n");
diff --git a/examples/dvbinfo/libdvbpsi.c b/examples/dvbinfo/libdvbpsi.c
index b31a920..599654f 100644
--- a/examples/dvbinfo/libdvbpsi.c
+++ b/examples/dvbinfo/libdvbpsi.c
@@ -331,6 +331,7 @@ static void dvbpsi_message(dvbpsi_t *p_dvbpsi, const dvbpsi_msg_level_t level, c
     /* See dvbinfo.h for the definition of these log levels.*/
     int code = 0;
     const char *psz_level;
+    ts_stream_t *stream;
 
     switch(level)
     {
@@ -341,7 +342,7 @@ static void dvbpsi_message(dvbpsi_t *p_dvbpsi, const dvbpsi_msg_level_t level, c
             return;
     }
 
-    ts_stream_t *stream = (ts_stream_t *)p_dvbpsi->p_sys;
+    stream = (ts_stream_t *)p_dvbpsi->p_sys;
     if (stream && stream->pf_log)
     {
         stream->pf_log(stream->cb_data, code, msg);
@@ -480,12 +481,14 @@ static void summary(FILE *fd, ts_stream_t *stream)
     uint64_t i_packets = 0;
     mtime_t i_first_pcr = 0, i_last_pcr = 0;
     mtime_t start = 0, end = 0;
+	int i_pid;
+	double total_bitrate;
 
     fprintf(fd, "\n---------------------------------------------------------\n");
     fprintf(fd, "\nSummary: Bandwidth\n");
 
     /* Find PCR PID and get pcr timestamps */
-    for (int i_pid = 0; i_pid < 8192; i_pid++)
+    for (i_pid = 0; i_pid < 8192; i_pid++)
     {
         if (stream->pid[i_pid].b_pcr)
         {
@@ -499,14 +502,14 @@ static void summary(FILE *fd, ts_stream_t *stream)
         }
     }
 
-    for (int i_pid = 0; i_pid < 8192; i_pid++)
+    for (i_pid = 0; i_pid < 8192; i_pid++)
     {
         if (stream->pid[i_pid].b_seen)
         {
+            double bitrate = 0;
             fprintf(fd, "Found PID: %4d (0x%4x), DRM: %s,", i_pid, i_pid,
                    (stream->pid[i_pid].i_transport_scrambling_control != 0x00) ? "yes" : " no" );
 
-            double bitrate = 0;
             if ((end - start) > 0)
             {
                 bitrate = (double) (stream->pid[i_pid].i_packets * 188 * 8) /
@@ -525,7 +528,7 @@ static void summary(FILE *fd, ts_stream_t *stream)
             i_last_pcr = (i_last_pcr > end) ? i_last_pcr : end;
         }
     }
-    double total_bitrate = (double)(((i_packets*188) + stream->i_lost_bytes) * 8)/((double)(i_last_pcr - i_first_pcr)/1000.0);
+    total_bitrate = (double)(((i_packets*188) + stream->i_lost_bytes) * 8)/((double)(i_last_pcr - i_first_pcr)/1000.0);
     fprintf(fd, "\nTotal bitrate %0.4f kbits/s\n", total_bitrate);
 
     fprintf(fd, "Number of packets: %"PRId64", stuffing %"PRId64" packets, lost %"PRId64" bytes\n",
@@ -537,6 +540,7 @@ static void summary(FILE *fd, ts_stream_t *stream)
 
 static void summary_table(FILE *fd, ts_stream_t *stream)
 {
+    ts_pmt_t *p_pmt;
     fprintf(fd, "\n---------------------------------------------------------\n");
     fprintf(fd, "\nSummary: Table\n");
 
@@ -544,7 +548,7 @@ static void summary_table(FILE *fd, ts_stream_t *stream)
     if (stream->pat.handle)
         ts_header_dump(fd, stream->pat.pid);
     fprintf(fd, "\nTable: PMT\n");
-    ts_pmt_t *p_pmt = stream->pmt;
+    p_pmt = stream->pmt;
     while (p_pmt)
     {
         if (p_pmt->handle)
@@ -569,11 +573,12 @@ static void summary_table(FILE *fd, ts_stream_t *stream)
 
 static void summary_packet(FILE *fd, ts_stream_t *stream)
 {
+	int i_pid;
     fprintf(fd, "\n---------------------------------------------------------\n");
     fprintf(fd, "\nSummary: Packet\n");
 
     /* Find PCR PID and get pcr timestamps */
-    for (int i_pid = 0; i_pid < 8192; i_pid++)
+    for (i_pid = 0; i_pid < 8192; i_pid++)
     {
         ts_pid_t *ts = &stream->pid[i_pid];
         ts_header_dump(fd, ts);
@@ -974,8 +979,9 @@ static void DumpStreamIdentifierDescriptor(dvbpsi_stream_identifier_dr_t* p_si_d
  *****************************************************************************/
 static void DumpCAIdentifierDescriptor(dvbpsi_ca_identifier_dr_t *p_ca_descriptor)
 {
+	int i;
     printf("CA system id\n");
-    for(int i = 0; i < p_ca_descriptor->i_number; i++ )
+    for(i = 0; i < p_ca_descriptor->i_number; i++ )
         printf("\t%d: %d\n", i, p_ca_descriptor->p_system[i].i_ca_system_id);
 }
 
@@ -989,6 +995,7 @@ typedef struct {
 
 static const char *GetContentSubCategory( const int i_type )
 {
+	unsigned int i;
     dr_content_category_t content_subcategory[] = {
         /* Movie/Drama */
         { DVBPSI_CONTENT_MOVIE_GENERAL, "General" },
@@ -1098,7 +1105,7 @@ static const char *GetContentSubCategory( const int i_type )
         { DVBPSI_CONTENT_SPECIAL_USERDEFINED4, "User Defined 4" }
     };
 
-    for (unsigned int i = 0; i < ARRAY_SIZE(content_subcategory); i++)
+    for (i = 0; i < ARRAY_SIZE(content_subcategory); i++)
     {
         if (i_type == content_subcategory[i].i_category)
             return content_subcategory[i].p_category;
@@ -1108,6 +1115,7 @@ static const char *GetContentSubCategory( const int i_type )
 
 static void DumpContentDescriptor(dvbpsi_content_dr_t *p_content_descriptor)
 {
+	int i;
     dr_content_category_t content_category[] = {
         { DVBPSI_CONTENT_CAT_UNDEFINED, "Undefined" },
         { DVBPSI_CONTENT_CAT_MOVIE, "Movie" },
@@ -1129,7 +1137,7 @@ static void DumpContentDescriptor(dvbpsi_content_dr_t *p_content_descriptor)
     };
 
     printf("Content\n");
-    for(int i = 0; i < p_content_descriptor->i_contents_number; i++)
+    for(i = 0; i < p_content_descriptor->i_contents_number; i++)
     {
         int i_type = p_content_descriptor->p_content[i].i_type;
         int i_category = DVBPSI_GetContentCategoryFromType(i_type);
@@ -1354,9 +1362,10 @@ static void DumpCUEIDescriptor(dvbpsi_cuei_dr_t* p_cuei_descriptor)
  *****************************************************************************/
 static void DumpSISSegmentationDescriptor(dvbpsi_descriptor_t* p_descriptor)
 {
+	int i;
     /* FIXME: decode segmentation descriptor */
     printf("\"");
-    for (int i = 4; i < p_descriptor->i_length; i++)
+    for (i = 4; i < p_descriptor->i_length; i++)
         printf("%c", p_descriptor->p_data[i]);
     printf("\" (%s)\n", "segmentation descriptor");
 }
@@ -1368,8 +1377,9 @@ static void DumpSISDescriptors(const char* str, dvbpsi_descriptor_t* p_descripto
 {
     while (p_descriptor)
     {
+		uint32_t i_identifier;
         assert(p_descriptor->i_length >= 4);
-        uint32_t i_identifier = ((uint32_t)p_descriptor->p_data[0] << 24) |
+        i_identifier = ((uint32_t)p_descriptor->p_data[0] << 24) |
                                 ((uint32_t)p_descriptor->p_data[1] << 16) |
                                 ((uint32_t)p_descriptor->p_data[2] << 8)  |
                                 ((uint32_t)p_descriptor->p_data[3]);
@@ -1384,9 +1394,10 @@ static void DumpSISDescriptors(const char* str, dvbpsi_descriptor_t* p_descripto
         {
             case 0x00: /* avail_descriptor */
             {
+				uint32_t id;
                 assert(p_descriptor->i_length >= 8);
 
-                uint32_t id = ((uint32_t)p_descriptor->p_data[4] << 24) |
+                id = ((uint32_t)p_descriptor->p_data[4] << 24) |
                               ((uint32_t)p_descriptor->p_data[5] << 16) |
                               ((uint32_t)p_descriptor->p_data[6] << 8)  |
                               ((uint32_t)p_descriptor->p_data[7]);
@@ -1396,11 +1407,14 @@ static void DumpSISDescriptors(const char* str, dvbpsi_descriptor_t* p_descripto
             }
             case 0x01: /* DTMF_descriptor */
             {
+				double i_preroll;
+				uint8_t i_dtmf_count;
+				int i;
                 assert(p_descriptor->i_length >= 6);
-                double i_preroll = p_descriptor->p_data[4] * 0.1;
-                uint8_t i_dtmf_count = (p_descriptor->p_data[5] & 0xE0);
+                i_preroll = p_descriptor->p_data[4] * 0.1;
+                i_dtmf_count = (p_descriptor->p_data[5] & 0xE0);
                 printf("\"");
-                for (int i = 0; i < i_dtmf_count; i++)
+                for (i = 0; i < i_dtmf_count; i++)
                      printf("%c", p_descriptor->p_data[6 + i]);
                 printf("\" preroll %.2f sec. (%s)\n", i_preroll, "DTMF descriptor");
                 break;
@@ -1410,11 +1424,14 @@ static void DumpSISDescriptors(const char* str, dvbpsi_descriptor_t* p_descripto
                 break;
             /* 0x03 - 0xFF : Reserved for future SCTE splice_descriptors */
             default:
+			{
+				int i;
                 printf("\"");
-                for (int i = 4; i < p_descriptor->i_length; i++)
+                for (i = 4; i < p_descriptor->i_length; i++)
                      printf("%c", p_descriptor->p_data[i]);
                 printf("\" (%s)\n", GetDescriptorName(p_descriptor->i_tag));
                 break;
+			}
         }
         p_descriptor = p_descriptor->p_next;
     }
@@ -1468,6 +1485,7 @@ static void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descriptor)
 {
     while (p_descriptor)
     {
+		int i;
         printf("%s 0x%02x : ", str, p_descriptor->i_tag);
         switch (p_descriptor->i_tag)
         {
@@ -1476,7 +1494,7 @@ static void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descriptor)
                    or ISO/IEC 14496-2 visual streams */
             case 0x28:
                 printf("\"");
-                for(int i = 0; i < p_descriptor->i_length; i++)
+                for(i = 0; i < p_descriptor->i_length; i++)
                 {
                     switch(p_descriptor->p_data[i])
                     {
@@ -1527,7 +1545,7 @@ static void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descriptor)
                 break;
             default:
                 printf("\"");
-                for (int i = 0; i < p_descriptor->i_length; i++)
+                for (i = 0; i < p_descriptor->i_length; i++)
                      printf("%c", p_descriptor->p_data[i]);
                 printf("\" (%s)\n", GetDescriptorName(p_descriptor->i_tag));
                 break;
@@ -1614,10 +1632,11 @@ static void handle_EIT(void* p_data, dvbpsi_eit_t* p_eit)
 
 static void handle_TOT(void* p_data, dvbpsi_tot_t* p_tot)
 {
+	uint8_t table_id;
     //ts_stream_t* p_stream = (ts_stream_t*) p_data;
 
     printf("\n");
-    uint8_t table_id = (p_tot->p_first_descriptor != NULL) ? 0x73 : 0x70;
+    table_id = (p_tot->p_first_descriptor != NULL) ? 0x73 : 0x70;
     if (table_id == 0x70) /* TDT */
         printf("  TDT: Time and Date Table\n");
     else if (table_id == 0x73) /* TOT */
@@ -1670,6 +1689,7 @@ static const char *GetATSCTableType(const int i_type)
 static void handle_atsc_MGT(void *p_data, dvbpsi_atsc_mgt_t *p_mgt)
 {
     ts_stream_t* p_stream = (ts_stream_t*) p_data;
+    dvbpsi_atsc_mgt_table_t   *p_table = p_mgt->p_first_table;
 
     printf("\n");
     printf("  ATSC MGT: Master Guide Table\n");
@@ -1679,7 +1699,6 @@ static void handle_atsc_MGT(void *p_data, dvbpsi_atsc_mgt_t *p_mgt)
     printf("\tTable ID extension: %d\n", p_mgt->i_table_id_ext);
     printf("\tProtocol version: %d\n", p_mgt->i_protocol); /* PSIP protocol version */
 
-    dvbpsi_atsc_mgt_table_t   *p_table = p_mgt->p_first_table;
     while (p_table)
     {
         /* Attach new ATSC EIT decoder */
@@ -1869,6 +1888,11 @@ static void handle_atsc_ETT(void* p_data, dvbpsi_atsc_ett_t* p_ett)
 static void handle_atsc_STT(void* p_data, dvbpsi_atsc_stt_t *p_stt)
 {
     //ts_stream_t* p_stream = (ts_stream_t*) p_data;
+    /* decode daylight savings */
+    bool b_status = (p_stt->i_daylight_savings & 0x01);
+    uint8_t i_day_of_month = ((p_stt->i_daylight_savings & 0x00F8) >> 3);
+    uint8_t i_hour = (p_stt->i_daylight_savings >> 8);
+
 
     printf("\n");
     printf("  ATSC STT: System Time Table\n");
@@ -1879,11 +1903,6 @@ static void handle_atsc_STT(void* p_data, dvbpsi_atsc_stt_t *p_stt)
     printf("\tSystem time (GPS): %d seconds\n", p_stt->i_system_time);
     printf("\tGPS-UTC Offset   : %d seconds\n", p_stt->i_gps_utc_offset);
 
-    /* decode daylight savings */
-    bool b_status = (p_stt->i_daylight_savings & 0x01);
-    uint8_t i_day_of_month = ((p_stt->i_daylight_savings & 0x00F8) >> 3);
-    uint8_t i_hour = (p_stt->i_daylight_savings >> 8);
-
     printf("\tDaylight savings : %s\n", b_status ? "on" : "off" );
     printf("\t\tDay of month: %d\n", i_day_of_month);
     printf("\t\tHour of day : %d\n", i_hour);
@@ -2193,13 +2212,16 @@ error:
 
 void libdvbpsi_exit(ts_stream_t *stream)
 {
+   ts_pmt_t *p_pmt = stream->pmt;
+   ts_pmt_t *p_prev = NULL;
+   ts_atsc_eit_t *p_atsc_eit;
+   ts_atsc_eit_t *p_atsc_prev;
+
    summary(stdout, stream);
 
    if (dvbpsi_decoder_present(stream->pat.handle))
        dvbpsi_pat_detach(stream->pat.handle);
 
-   ts_pmt_t *p_pmt = stream->pmt;
-   ts_pmt_t *p_prev = NULL;
    while (p_pmt)
    {
        dvbpsi_t *handle = p_pmt->handle;
@@ -2216,8 +2238,8 @@ void libdvbpsi_exit(ts_stream_t *stream)
        free(p_prev);
    }
 
-   ts_atsc_eit_t *p_atsc_eit = stream->atsc_eit;
-   ts_atsc_eit_t *p_atsc_prev = NULL;
+   p_atsc_eit = stream->atsc_eit;
+   p_atsc_prev = NULL;
    while (p_atsc_eit)
    {
        dvbpsi_t *handle = p_atsc_eit->handle;
@@ -2286,11 +2308,17 @@ bool libdvbpsi_process(ts_stream_t *stream, uint8_t *buf, ssize_t length, mtime_
 {
     mtime_t  i_prev_pcr = 0;  /* 33 bits */
     int      i_old_cc = -1;
+	ssize_t i;
 
-    for (ssize_t i = 0; i < length; i += 188)
+    for (i = 0; i < length; i += 188)
     {
         /* check sync */
         ssize_t i_lost = check_sync_word(buf+i, length - i);
+		uint8_t* p_tmp;
+		uint16_t i_pid;
+		int i_cc;
+		bool b_discontinuity_seen;
+
         if (i_lost > 0)
         {
             stream->i_lost_bytes += i_lost;
@@ -2305,10 +2333,10 @@ bool libdvbpsi_process(ts_stream_t *stream, uint8_t *buf, ssize_t length, mtime_
         assert(buf[i] == 0x47);
 
         /* parse packet */
-        uint8_t  *p_tmp = &buf[i];
-        uint16_t i_pid = ((uint16_t)(p_tmp[1] & 0x1f) << 8) + p_tmp[2];
-        int      i_cc = (p_tmp[3] & 0x0f);
-        bool     b_discontinuity_seen = false;
+        p_tmp = &buf[i];
+        i_pid = ((uint16_t)(p_tmp[1] & 0x1f) << 8) + p_tmp[2];
+        i_cc = (p_tmp[3] & 0x0f);
+        b_discontinuity_seen = false;
 
         /* keep track nr of packets for this ES */
         stream->pid[i_pid].i_packets++;
@@ -2346,6 +2374,7 @@ bool libdvbpsi_process(ts_stream_t *stream, uint8_t *buf, ssize_t length, mtime_
         else
         {
             ts_pmt_t *p = stream->pmt;
+            ts_atsc_eit_t *p_atsc_eit;
             while(p)
             {
                 if (p->pid_pmt->i_pid == i_pid)
@@ -2353,7 +2382,7 @@ bool libdvbpsi_process(ts_stream_t *stream, uint8_t *buf, ssize_t length, mtime_
                 p = p->p_next;
             }
 
-            ts_atsc_eit_t *p_atsc_eit = stream->atsc_eit;
+            p_atsc_eit = stream->atsc_eit;
             while (p_atsc_eit)
             {
                 if (p_atsc_eit->pid->i_pid == i_pid)
@@ -2403,6 +2432,7 @@ bool libdvbpsi_process(ts_stream_t *stream, uint8_t *buf, ssize_t length, mtime_
         {
             bool b_pcr  = (p_tmp[5]&0x10) == 0x10;  /* PCR flag */
             bool b_opcr = (p_tmp[5]&0x08) == 0x08;  /* OPCR flag */
+            uint32_t i_ext = 5;
 
             stream->pid[i_pid].b_discontinuity_indicator = (p_tmp[5]&0x80) == 0x80;
             stream->pid[i_pid].b_random_access_indicator = (p_tmp[5]&0x40) == 0x40;
@@ -2411,7 +2441,6 @@ bool libdvbpsi_process(ts_stream_t *stream, uint8_t *buf, ssize_t length, mtime_
             stream->pid[i_pid].b_transport_private_data = (p_tmp[5]&0x02) == 0x02;
             stream->pid[i_pid].b_adaptation_field_extension = (p_tmp[5]&0x01) == 0x01;
 
-            uint32_t i_ext = 5;
 
             if (b_pcr) i_ext += 6;
 
@@ -2473,10 +2502,12 @@ bool libdvbpsi_process(ts_stream_t *stream, uint8_t *buf, ssize_t length, mtime_
 
             if (stream->pid[i_pid].b_adaptation_field_extension)
             {
+				uint8_t *p_ext;
+				uint32_t i_seamless_splice;
                 /* i_ext is start of adaptation_extension field */
                 i_ext++;
-                uint8_t *p_ext = &p_tmp[i_ext];
-                uint32_t i_seamless_splice = i_ext;
+                p_ext = &p_tmp[i_ext];
+                i_seamless_splice = i_ext;
 
                 stream->pid[i_pid].i_adaptation_field_extension_length = p_ext[0];
 
diff --git a/examples/dvbinfo/tcp.c b/examples/dvbinfo/tcp.c
index 3a2726e..7f75d28 100644
--- a/examples/dvbinfo/tcp.c
+++ b/examples/dvbinfo/tcp.c
@@ -90,12 +90,13 @@ int tcp_open(const char *ipaddress, int port)
 {
     int s_ctl = -1;
     int result = -1;
+    struct addrinfo hints, *addr;
+    char *psz_service;
+	struct addrinfo* ptr;
 
     if (!ipaddress) return -1;
 
     /* only support ipv4 */
-    struct addrinfo hints, *addr;
-    char *psz_service;
 
     if ((port > 65535) || (port < 0))
     {
@@ -119,9 +120,10 @@ int tcp_open(const char *ipaddress, int port)
         return -1;
     }
 
-    for (struct addrinfo *ptr = addr; ptr != NULL; ptr = ptr->ai_next )
+    for (ptr = addr; ptr != NULL; ptr = ptr->ai_next )
     {
         int sflags = 0;
+		int k = 1;
 #ifdef SOCK_CLOEXEC
         sflags = SOCK_CLOEXEC;
 #endif
@@ -141,7 +143,7 @@ int tcp_open(const char *ipaddress, int port)
         }
 #endif
 
-        if (setsockopt (s_ctl, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int)) < 0)
+        if (setsockopt (s_ctl, SOL_SOCKET, SO_REUSEADDR, &k, sizeof (int)) < 0)
             perror("tcp setsockopt error");
 
         result = connect( s_ctl, ptr->ai_addr, ptr->ai_addrlen );
diff --git a/examples/dvbinfo/udp.c b/examples/dvbinfo/udp.c
index 030add3..dc6b875 100644
--- a/examples/dvbinfo/udp.c
+++ b/examples/dvbinfo/udp.c
@@ -211,12 +211,13 @@ int udp_open(const char *interface, const char *ipaddress, int port)
 {
     int s_ctl = -1;
     int result = -1;
+    struct addrinfo hints, *addr;
+    char *psz_service;
+	struct addrinfo* ptr;
 
     if (!ipaddress) return -1;
 
     /* only support ipv4 */
-    struct addrinfo hints, *addr;
-    char *psz_service;
 
     if ((port > 65535) || (port < 0))
     {
@@ -240,9 +241,11 @@ int udp_open(const char *interface, const char *ipaddress, int port)
         return -1;
     }
 
-    for (struct addrinfo *ptr = addr; ptr != NULL; ptr = ptr->ai_next )
+    for (ptr = addr; ptr != NULL; ptr = ptr->ai_next )
     {
         int sflags = 0;
+		int k = 0x80000;
+        const struct sockaddr_storage *saddr;
 #ifdef SOCK_CLOEXEC
         sflags = SOCK_CLOEXEC;
 #endif
@@ -265,14 +268,15 @@ int udp_open(const char *interface, const char *ipaddress, int port)
         /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s)
          * to avoid packet loss caused in case of scheduling hiccups */
         if (setsockopt (s_ctl, SOL_SOCKET, SO_RCVBUF,
-                    (void *)&(int){ 0x80000 }, sizeof (int)) < 0)
+                    (void *)&k, sizeof (int)) < 0)
             perror("udp setsockopt error");
 
         if (setsockopt (s_ctl, SOL_SOCKET, SO_SNDBUF,
-                    (void *)&(int){ 0x80000 }, sizeof (int)) < 0)
+                    (void *)&k, sizeof (int)) < 0)
             perror("udp setsockopt error");
 
-        if (setsockopt (s_ctl, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int)) < 0)
+		k = 1;
+        if (setsockopt (s_ctl, SOL_SOCKET, SO_REUSEADDR, &k, sizeof (int)) < 0)
             perror("udp setsockopt error");
 
         result = bind(s_ctl, ptr->ai_addr, ptr->ai_addrlen);
@@ -284,7 +288,7 @@ int udp_open(const char *interface, const char *ipaddress, int port)
             continue;
         }
 
-        const struct sockaddr_storage *saddr = (const struct sockaddr_storage *)&ptr->ai_addr;
+        saddr = (const struct sockaddr_storage *)&ptr->ai_addr;
         if (is_multicast(saddr, ptr->ai_addrlen) &&
             mcast_connect(s_ctl, NULL, saddr, ptr->ai_addrlen))
         {
diff --git a/examples/get_pcr_pid.c b/examples/get_pcr_pid.c
index 322bb72..1d71962 100644
--- a/examples/get_pcr_pid.c
+++ b/examples/get_pcr_pid.c
@@ -184,7 +184,7 @@ static void TSHandle( uint8_t *p_ts )
 int main( int i_argc, char **pp_argv )
 {
     uint8_t *p_buffer;
-    int result = EXIT_FAILURE;
+    int result = EXIT_FAILURE, i;
 
     if ( i_argc < 2 || i_argc > 3 || !strcmp( pp_argv[1], "-" ) )
     {
@@ -215,7 +215,6 @@ int main( int i_argc, char **pp_argv )
 
     for ( ; ; )
     {
-        int i;
         ssize_t i_ret;
 
         if ( (i_ret = read( i_fd, p_buffer, TS_SIZE * READ_ONCE )) < 0 )
@@ -237,7 +236,7 @@ int main( int i_argc, char **pp_argv )
     }
     free( p_buffer );
 
-    for( int i = 0; i < MAX_PROGRAMS; i++)
+    for(i = 0; i < MAX_PROGRAMS; i++)
     {
         if (p_pmt_dvbpsi_fds[i])
         {
diff --git a/src/demux.c b/src/demux.c
index adbf1e1..f74f58c 100644
--- a/src/demux.c
+++ b/src/demux.c
@@ -53,10 +53,11 @@ bool dvbpsi_AttachDemux(dvbpsi_t *            p_dvbpsi,
                         dvbpsi_demux_new_cb_t pf_new_cb,
                         void *                p_new_cb_data)
 {
+    dvbpsi_demux_t *p_demux;
+
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder == NULL);
 
-    dvbpsi_demux_t *p_demux;
     p_demux = (dvbpsi_demux_t*) dvbpsi_decoder_new(&dvbpsi_Demux, 4096, true,
                                                    sizeof(dvbpsi_demux_t));
     if (p_demux == NULL)
@@ -101,11 +102,13 @@ dvbpsi_demux_subdec_t * dvbpsi_demuxGetSubDec(dvbpsi_demux_t * p_demux,
  *****************************************************************************/
 void dvbpsi_Demux(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section)
 {
+    dvbpsi_demux_t * p_demux;
+    dvbpsi_demux_subdec_t * p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t * p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_decoder;
-    dvbpsi_demux_subdec_t * p_subdec = dvbpsi_demuxGetSubDec(p_demux, p_section->i_table_id,
+    p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_decoder;
+    p_subdec = dvbpsi_demuxGetSubDec(p_demux, p_section->i_table_id,
                                                              p_section->i_extension);
     if (p_subdec == NULL)
     {
@@ -132,11 +135,14 @@ void dvbpsi_Demux(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section)
  *****************************************************************************/
 void dvbpsi_DetachDemux(dvbpsi_t *p_dvbpsi)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_demux_subdec_t* p_subdec;
+
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_decoder;
-    dvbpsi_demux_subdec_t* p_subdec = p_demux->p_first_subdec;
+    p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_decoder;
+    p_subdec = p_demux->p_first_subdec;
 
     while (p_subdec)
     {
@@ -164,14 +170,16 @@ dvbpsi_demux_subdec_t *dvbpsi_NewDemuxSubDecoder(const uint8_t i_table_id,
                                                  dvbpsi_demux_gather_cb_t pf_gather,
                                                  dvbpsi_decoder_t *p_decoder)
 {
+    dvbpsi_demux_subdec_t *p_subdec = calloc(1, sizeof(dvbpsi_demux_subdec_t));
+	uint32_t i_id;
+
     assert(pf_gather);
     assert(pf_detach);
 
-    dvbpsi_demux_subdec_t *p_subdec = calloc(1, sizeof(dvbpsi_demux_subdec_t));
     if (p_subdec == NULL)
         return NULL;
 
-    uint32_t i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;
+    i_id = (uint32_t)i_table_id << 16 | (uint32_t)i_extension;
 
     /* subtable decoder configuration */
     p_subdec->i_id = i_id;
@@ -219,6 +227,8 @@ void dvbpsi_AttachDemuxSubDecoder(dvbpsi_demux_t *p_demux, dvbpsi_demux_subdec_t
  *****************************************************************************/
 void dvbpsi_DetachDemuxSubDecoder(dvbpsi_demux_t *p_demux, dvbpsi_demux_subdec_t *p_subdec)
 {
+    dvbpsi_demux_subdec_t** pp_prev_subdec;
+
     assert(p_demux);
     assert(p_demux->p_first_subdec);
 
@@ -227,7 +237,6 @@ void dvbpsi_DetachDemuxSubDecoder(dvbpsi_demux_t *p_demux, dvbpsi_demux_subdec_t
     if (!p_demux || !p_subdec)
         abort();
 
-    dvbpsi_demux_subdec_t** pp_prev_subdec;
     pp_prev_subdec = &p_demux->p_first_subdec;
     while(*pp_prev_subdec != p_subdec)
         pp_prev_subdec = &(*pp_prev_subdec)->p_next;
diff --git a/src/descriptor.c b/src/descriptor.c
index 4506ea2..36f3cb1 100644
--- a/src/descriptor.c
+++ b/src/descriptor.c
@@ -161,10 +161,11 @@ void dvbpsi_DeleteDescriptors(dvbpsi_descriptor_t* p_descriptor)
  *****************************************************************************/
 void *dvbpsi_DuplicateDecodedDescriptor(void *p_decoded, ssize_t i_size)
 {
+	void* p_duplicate;
     if (!p_decoded)
         return NULL;
 
-    void *p_duplicate = calloc(1, i_size);
+    p_duplicate = calloc(1, i_size);
     if (p_duplicate)
         memcpy(p_duplicate, p_decoded, i_size);
     return p_duplicate;
diff --git a/src/descriptors/dr_05.c b/src/descriptors/dr_05.c
index cf9487e..e19ee67 100644
--- a/src/descriptors/dr_05.c
+++ b/src/descriptors/dr_05.c
@@ -94,11 +94,12 @@ dvbpsi_registration_dr_t * dvbpsi_DecodeRegistrationDr(
 dvbpsi_descriptor_t * dvbpsi_GenRegistrationDr(dvbpsi_registration_dr_t *p_decoded,
                                                bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
     if (p_decoded->i_additional_length > 251)
         p_decoded->i_additional_length = 251;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x05, p_decoded->i_additional_length + 4, NULL);
 
     if (!p_descriptor)
diff --git a/src/descriptors/dr_09.c b/src/descriptors/dr_09.c
index c07053f..0d40c1c 100644
--- a/src/descriptors/dr_09.c
+++ b/src/descriptors/dr_09.c
@@ -88,11 +88,12 @@ dvbpsi_ca_dr_t * dvbpsi_DecodeCADr(dvbpsi_descriptor_t * p_descriptor)
 dvbpsi_descriptor_t * dvbpsi_GenCADr(dvbpsi_ca_dr_t * p_decoded,
                                      bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
     if (p_decoded->i_private_length > 251)
         p_decoded->i_private_length = 251;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x09, p_decoded->i_private_length + 4, NULL);
     if (!p_descriptor)
         return NULL;
diff --git a/src/descriptors/dr_0a.c b/src/descriptors/dr_0a.c
index 1c88263..803bcbb 100644
--- a/src/descriptors/dr_0a.c
+++ b/src/descriptors/dr_0a.c
@@ -47,6 +47,7 @@
 dvbpsi_iso639_dr_t * dvbpsi_DecodeISO639Dr(dvbpsi_descriptor_t * p_descriptor)
 {
     dvbpsi_iso639_dr_t * p_decoded;
+    int i = 0;
 
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x0a))
@@ -69,7 +70,6 @@ dvbpsi_iso639_dr_t * dvbpsi_DecodeISO639Dr(dvbpsi_descriptor_t * p_descriptor)
     if (p_decoded->i_code_count > 64)
         p_decoded->i_code_count = 64;
 
-    int i = 0;
     while( i < p_decoded->i_code_count )
     {
         p_decoded->code[i].iso_639_code[0] = p_descriptor->p_data[i*4];
@@ -90,17 +90,18 @@ dvbpsi_iso639_dr_t * dvbpsi_DecodeISO639Dr(dvbpsi_descriptor_t * p_descriptor)
 dvbpsi_descriptor_t * dvbpsi_GenISO639Dr(dvbpsi_iso639_dr_t * p_decoded,
                                          bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
+    int i = 0;
     if (p_decoded->i_code_count > 64)
         p_decoded->i_code_count = 64;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x0a, p_decoded->i_code_count * 4, NULL);
     if (!p_descriptor)
         return NULL;
 
     /* Encode data */
-    int i = 0;
     while( i < p_decoded->i_code_count )
     {
         p_descriptor->p_data[i*4] = p_decoded->code[i].iso_639_code[0];
diff --git a/src/descriptors/dr_0d.c b/src/descriptors/dr_0d.c
index bd8ee30..7aed4a8 100644
--- a/src/descriptors/dr_0d.c
+++ b/src/descriptors/dr_0d.c
@@ -92,11 +92,12 @@ dvbpsi_copyright_dr_t * dvbpsi_DecodeCopyrightDr(
 dvbpsi_descriptor_t * dvbpsi_GenCopyrightDr(dvbpsi_copyright_dr_t * p_decoded,
                                             bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
     if (p_decoded->i_additional_length > 251)
         p_decoded->i_additional_length = 251;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x0d, p_decoded->i_additional_length + 4, NULL);
     if (!p_descriptor)
         return NULL;
diff --git a/src/descriptors/dr_14.c b/src/descriptors/dr_14.c
index da5fc20..ba92933 100644
--- a/src/descriptors/dr_14.c
+++ b/src/descriptors/dr_14.c
@@ -42,11 +42,12 @@ Decode Assocation Tag Descriptor.
 static dvbpsi_association_tag_dr_t *NewAssociationTagDr(const size_t i_selector, const size_t i_private)
 {
     dvbpsi_association_tag_dr_t *p_tag;
+	size_t i_size;
 
     if ((i_selector <= 0) || (i_private <= 0))
         return NULL;
 
-    size_t i_size = sizeof(dvbpsi_association_tag_dr_t) + i_selector + i_private;
+    i_size = sizeof(dvbpsi_association_tag_dr_t) + i_selector + i_private;
     p_tag = (dvbpsi_association_tag_dr_t*) calloc(1, i_size);
     if (p_tag)
     {
diff --git a/src/descriptors/dr_41.c b/src/descriptors/dr_41.c
index db4ac3e..fd628cc 100644
--- a/src/descriptors/dr_41.c
+++ b/src/descriptors/dr_41.c
@@ -46,6 +46,8 @@ dvbpsi_service_list_dr_t* dvbpsi_DecodeServiceListDr(
                                         dvbpsi_descriptor_t * p_descriptor)
 {
     dvbpsi_service_list_dr_t * p_decoded;
+    unsigned int service_count = p_descriptor->i_length / 3;
+	uint8_t i;
 
     /* Check the tag */
     if (p_descriptor->i_tag != 0x41)
@@ -56,7 +58,6 @@ dvbpsi_service_list_dr_t* dvbpsi_DecodeServiceListDr(
         return p_descriptor->p_decoded;
 
     /* Check the length */
-    unsigned int service_count = p_descriptor->i_length / 3;
     if ((p_descriptor->i_length < 1) ||
         (p_descriptor->i_length % 3 != 0) ||
         (service_count>63))
@@ -70,7 +71,7 @@ dvbpsi_service_list_dr_t* dvbpsi_DecodeServiceListDr(
     /* Decode data */
     p_decoded->i_service_count = service_count;
 
-    for (uint8_t i = 0; i < p_decoded->i_service_count; i++ )
+    for (i = 0; i < p_decoded->i_service_count; i++ )
     {
     	p_decoded->i_service[i].i_service_id = ((uint16_t)(p_descriptor->p_data[i*3]) << 8)
                                       | p_descriptor->p_data[i*3+1];
@@ -90,18 +91,20 @@ dvbpsi_descriptor_t * dvbpsi_GenServiceListDr(
 		                        dvbpsi_service_list_dr_t * p_decoded,
                                         bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
+	uint8_t i;
     /* Check the length */
     if (p_decoded->i_service_count > 63)
         return NULL;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x83, p_decoded->i_service_count*3, NULL);
     if (!p_descriptor)
         return NULL;
 
     /* Encode data */
-    for (uint8_t i = 0; i < p_decoded->i_service_count; i++)
+    for (i = 0; i < p_decoded->i_service_count; i++)
     {
         p_descriptor->p_data[i*3] = p_decoded->i_service[i].i_service_id >> 8;
         p_descriptor->p_data[i*3+1] = p_decoded->i_service[i].i_service_id;
diff --git a/src/descriptors/dr_45.c b/src/descriptors/dr_45.c
index 7cf8b53..2132447 100644
--- a/src/descriptors/dr_45.c
+++ b/src/descriptors/dr_45.c
@@ -46,6 +46,9 @@
 dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
                                         dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_vbi_dr_t * p_decoded;
+    uint8_t i_services_number;
+	uint8_t i;
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x45))
         return NULL;
@@ -61,8 +64,7 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
         return NULL;
 
     /* */
-    dvbpsi_vbi_dr_t * p_decoded;
-    uint8_t i_services_number = p_descriptor->i_length / 2;
+    i_services_number = p_descriptor->i_length / 2;
     if (i_services_number > DVBPSI_VBI_DR_MAX)
         i_services_number = DVBPSI_VBI_DR_MAX;
 
@@ -73,9 +75,9 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
 
     p_decoded->i_services_number = i_services_number;
 
-    for (uint8_t i = 0; i < i_services_number; i++)
+    for (i = 0; i < i_services_number; i++)
     {
-        uint8_t i_lines = 0, i_data_service_id;
+        uint8_t i_lines = 0, i_data_service_id, n;
 
         i_data_service_id = ((uint8_t)(p_descriptor->p_data[3 * i + 2 + i_lines]));
         p_decoded->p_services[i].i_data_service_id = i_data_service_id;
@@ -83,7 +85,7 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
         i_lines = ((uint8_t)(p_descriptor->p_data[3 * i + 3]));
         p_decoded->p_services[i].i_lines = i_lines;
 
-        for (uint8_t n = 0; n < i_lines; n++)
+        for (n = 0; n < i_lines; n++)
         {
             if( (i_data_service_id >= 0x01) && (i_data_service_id <= 0x07) )
             {
@@ -106,23 +108,26 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
 dvbpsi_descriptor_t * dvbpsi_GenVBIDataDr(dvbpsi_vbi_dr_t * p_decoded,
                                           bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
+	uint8_t i;
     if (p_decoded->i_services_number > DVBPSI_VBI_DR_MAX)
         p_decoded->i_services_number = DVBPSI_VBI_DR_MAX;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x45, p_decoded->i_services_number * 5 , NULL);
     if (!p_descriptor)
         return NULL;
 
     /* Encode data */
-    for (uint8_t i = 0; i < p_decoded->i_services_number; i++)
+    for (i = 0; i < p_decoded->i_services_number; i++)
     {
+		uint8_t n;
         p_descriptor->p_data[5 * i + 3] =
                 ( (uint8_t) p_decoded->p_services[i].i_data_service_id );
 
         p_descriptor->p_data[5 * i + 4] = p_decoded->p_services[i].i_lines;
-        for (uint8_t n=0; n < p_decoded->p_services[i].i_lines; n++ )
+        for (n=0; n < p_decoded->p_services[i].i_lines; n++ )
         {
             if( (p_decoded->p_services[i].i_data_service_id >= 0x01) &&
                     (p_decoded->p_services[i].i_data_service_id <= 0x07) )
diff --git a/src/descriptors/dr_48.c b/src/descriptors/dr_48.c
index a348dc7..0cbc417 100644
--- a/src/descriptors/dr_48.c
+++ b/src/descriptors/dr_48.c
@@ -48,6 +48,7 @@
 dvbpsi_service_dr_t * dvbpsi_DecodeServiceDr(
                                         dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_service_dr_t * p_decoded;
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x48))
         return NULL;
@@ -60,7 +61,6 @@ dvbpsi_service_dr_t * dvbpsi_DecodeServiceDr(
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_service_dr_t * p_decoded;
     p_decoded = (dvbpsi_service_dr_t*)calloc(1, sizeof(dvbpsi_service_dr_t));
     if (!p_decoded)
         return NULL;
@@ -111,13 +111,14 @@ dvbpsi_service_dr_t * dvbpsi_DecodeServiceDr(
 dvbpsi_descriptor_t * dvbpsi_GenServiceDr(dvbpsi_service_dr_t * p_decoded,
                                           bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
     if (p_decoded->i_service_provider_name_length > 252)
         p_decoded->i_service_provider_name_length = 252;
     if (p_decoded->i_service_name_length > 252)
         p_decoded->i_service_name_length = 252;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x48, 3 + p_decoded->i_service_name_length +
                                  p_decoded->i_service_provider_name_length, NULL);
     if (!p_descriptor)
diff --git a/src/descriptors/dr_49.c b/src/descriptors/dr_49.c
index ba897e3..296ae4d 100644
--- a/src/descriptors/dr_49.c
+++ b/src/descriptors/dr_49.c
@@ -46,6 +46,8 @@ dvbpsi_country_availability_dr_t* dvbpsi_DecodeCountryAvailability(
                                         dvbpsi_descriptor_t * p_descriptor)
 {
     dvbpsi_country_availability_dr_t * p_decoded;
+	unsigned int code_count;
+	uint8_t i;
 
     /* Check the tag */
     if (p_descriptor->i_tag != 0x49)
@@ -56,7 +58,7 @@ dvbpsi_country_availability_dr_t* dvbpsi_DecodeCountryAvailability(
         return p_descriptor->p_decoded;
 
     /* Check the length */
-    unsigned int code_count = (p_descriptor->i_length-1) / 3;
+    code_count = (p_descriptor->i_length-1) / 3;
     if ((p_descriptor->i_length < 1) ||
         ((p_descriptor->i_length-1) % 3 != 0) ||
          (code_count > 83))
@@ -71,7 +73,7 @@ dvbpsi_country_availability_dr_t* dvbpsi_DecodeCountryAvailability(
     p_decoded->i_code_count = code_count;
     p_decoded->b_country_availability_flag = p_descriptor->p_data[0] & 0x80;
 
-    for (uint8_t i = 0; i < p_decoded->i_code_count; i++)
+    for (i = 0; i < p_decoded->i_code_count; i++)
     {
     	p_decoded->code[i].iso_639_code[0] = p_descriptor->p_data[1+i*3];
     	p_decoded->code[i].iso_639_code[1] = p_descriptor->p_data[2+i*3];
@@ -91,12 +93,14 @@ dvbpsi_descriptor_t * dvbpsi_GenCountryAvailabilityDr(
 		                        dvbpsi_country_availability_dr_t * p_decoded,
                                         bool b_duplicate)
 {
-    /* Check the length */    
+    dvbpsi_descriptor_t * p_descriptor;
+	uint8_t i;
+    /* Check the length */
     if (p_decoded->i_code_count > 83) 
         return NULL;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x83, 1+p_decoded->i_code_count*3, NULL);
     if (!p_descriptor)
         return NULL;
@@ -104,7 +108,7 @@ dvbpsi_descriptor_t * dvbpsi_GenCountryAvailabilityDr(
     /* Encode data */
     p_descriptor->p_data[0] = (p_decoded->b_country_availability_flag) ? 0x80: 0x00;
 
-    for (uint8_t i = 0; i < p_decoded->i_code_count; i++)
+    for (i = 0; i < p_decoded->i_code_count; i++)
     {
         p_descriptor->p_data[1+i*3] = p_decoded->code[i].iso_639_code[0];
         p_descriptor->p_data[2+i*3] = p_decoded->code[i].iso_639_code[1];
diff --git a/src/descriptors/dr_4a.c b/src/descriptors/dr_4a.c
index 590a122..340d62b 100644
--- a/src/descriptors/dr_4a.c
+++ b/src/descriptors/dr_4a.c
@@ -44,6 +44,9 @@
  *****************************************************************************/
 dvbpsi_linkage_dr_t* dvbpsi_DecodeLinkageDr(dvbpsi_descriptor_t * p_descriptor)
 {
+    int handover_type = 0, origin_type = 0;
+    dvbpsi_linkage_dr_t * p_decoded;
+    int i = 7;
     /* Check the tag */
     if (p_descriptor->i_tag != 0x4A)
         return NULL;
@@ -53,7 +56,6 @@ dvbpsi_linkage_dr_t* dvbpsi_DecodeLinkageDr(dvbpsi_descriptor_t * p_descriptor)
         return p_descriptor->p_decoded;
 
     /* Check the length */
-    int handover_type = 0, origin_type = 0;
     if (p_descriptor->p_data[6] == 0x08)
     {
         handover_type = p_descriptor->p_data[7] & 0xF0 >> 4;
@@ -73,13 +75,11 @@ dvbpsi_linkage_dr_t* dvbpsi_DecodeLinkageDr(dvbpsi_descriptor_t * p_descriptor)
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_linkage_dr_t * p_decoded;
     p_decoded = (dvbpsi_linkage_dr_t*)calloc(1, sizeof(dvbpsi_linkage_dr_t));
     if (!p_decoded)
         return NULL;
 
     /* Decode data */
-    int i = 7;
     p_decoded->i_transport_stream_id = p_descriptor->p_data[0] << 8
                                        | p_descriptor->p_data[1];
     p_decoded->i_original_network_id = p_descriptor->p_data[2] << 8
@@ -141,6 +141,7 @@ dvbpsi_descriptor_t * dvbpsi_GenLinkageDr(dvbpsi_linkage_dr_t * p_decoded,
     /* Check the length */
     int last_pos;
     int length = 7;
+    dvbpsi_descriptor_t * p_descriptor;
 
     if (p_decoded->i_linkage_type == 0x08)
     {
@@ -159,7 +160,7 @@ dvbpsi_descriptor_t * dvbpsi_GenLinkageDr(dvbpsi_linkage_dr_t * p_decoded,
         return NULL;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x4a, p_decoded->i_private_data_length+length, NULL);
     if (!p_descriptor)
         return NULL;
diff --git a/src/descriptors/dr_4b.c b/src/descriptors/dr_4b.c
index dd75bb7..c19a3c3 100644
--- a/src/descriptors/dr_4b.c
+++ b/src/descriptors/dr_4b.c
@@ -44,6 +44,8 @@
  *****************************************************************************/
 dvbpsi_nvod_ref_dr_t* dvbpsi_DecodeNVODReferenceDr(dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_nvod_ref_dr_t * p_decoded;
+	int i;
     /* Check the tag */
     if (p_descriptor->i_tag != 0x4B)
         return NULL;
@@ -59,7 +61,6 @@ dvbpsi_nvod_ref_dr_t* dvbpsi_DecodeNVODReferenceDr(dvbpsi_descriptor_t * p_descr
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_nvod_ref_dr_t * p_decoded;
     p_decoded = (dvbpsi_nvod_ref_dr_t*)calloc(1, sizeof(dvbpsi_nvod_ref_dr_t));
     if (!p_decoded)
         return NULL;
@@ -69,7 +70,7 @@ dvbpsi_nvod_ref_dr_t* dvbpsi_DecodeNVODReferenceDr(dvbpsi_descriptor_t * p_descr
     if (p_decoded->i_references > 43)
 	p_decoded->i_references = 43;
 
-    for (int i = 0; i < p_decoded->i_references; i++)
+    for (i = 0; i < p_decoded->i_references; i++)
     {
       int pos = i*6;
       p_decoded->p_nvod_refs[i].i_transport_stream_id = p_descriptor->p_data[pos] << 8
@@ -91,6 +92,7 @@ dvbpsi_nvod_ref_dr_t* dvbpsi_DecodeNVODReferenceDr(dvbpsi_descriptor_t * p_descr
 dvbpsi_descriptor_t * dvbpsi_GenNVODReferenceDr(dvbpsi_nvod_ref_dr_t * p_decoded,
                                           bool b_duplicate)
 {
+    int pos = 0, i;
     /* Create the descriptor */
     dvbpsi_descriptor_t * p_descriptor =
             dvbpsi_NewDescriptor(0x4b, p_decoded->i_references * 6, NULL);
@@ -101,8 +103,7 @@ dvbpsi_descriptor_t * dvbpsi_GenNVODReferenceDr(dvbpsi_nvod_ref_dr_t * p_decoded
 	p_decoded->i_references = 43;
 
     /* Encode data */
-    int pos = 0;
-    for (int i = 0; i < p_decoded->i_references; i++ )
+    for (i = 0; i < p_decoded->i_references; i++ )
     {
     	p_descriptor->p_data[pos++] = p_decoded->p_nvod_refs[i].i_transport_stream_id >> 8;
         p_descriptor->p_data[pos++] = p_decoded->p_nvod_refs[i].i_transport_stream_id;
diff --git a/src/descriptors/dr_4c.c b/src/descriptors/dr_4c.c
index 48b8431..6e61c59 100644
--- a/src/descriptors/dr_4c.c
+++ b/src/descriptors/dr_4c.c
@@ -44,6 +44,7 @@
  *****************************************************************************/
 dvbpsi_tshifted_service_dr_t* dvbpsi_DecodeTimeShiftedServiceDr(dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_tshifted_service_dr_t *p_decoded;
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x4c))
         return NULL;
@@ -56,7 +57,6 @@ dvbpsi_tshifted_service_dr_t* dvbpsi_DecodeTimeShiftedServiceDr(dvbpsi_descripto
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_tshifted_service_dr_t *p_decoded;
     p_decoded = (dvbpsi_tshifted_service_dr_t*)calloc(1, sizeof(dvbpsi_tshifted_service_dr_t));
     if (!p_decoded)
         return NULL;
diff --git a/src/descriptors/dr_4e.c b/src/descriptors/dr_4e.c
index 5fcb880..98a0d10 100644
--- a/src/descriptors/dr_4e.c
+++ b/src/descriptors/dr_4e.c
@@ -110,10 +110,12 @@ dvbpsi_descriptor_t * dvbpsi_GenExtendedEventDr(dvbpsi_extended_event_dr_t * p_d
 {
     int i_len;
     int i_len2;
+	int i;
+	uint8_t* p;
     dvbpsi_descriptor_t * p_descriptor;
 
     i_len2 = 0;
-    for (int i = 0; i < p_decoded->i_entry_count; i++)
+    for (i = 0; i < p_decoded->i_entry_count; i++)
         i_len2 += 2 + p_decoded->i_item_description_length[i] + p_decoded->i_item_length[i];
     i_len = 1 + 3 + 1 + i_len2 + 1 + p_decoded->i_text_length;
 
@@ -122,7 +124,7 @@ dvbpsi_descriptor_t * dvbpsi_GenExtendedEventDr(dvbpsi_extended_event_dr_t * p_d
     if (!p_descriptor)
         return NULL;
 
-    uint8_t *p = &p_descriptor->p_data[0];
+    p = &p_descriptor->p_data[0];
 
     /* Encode data */
     p[0] = (p_decoded->i_descriptor_number << 4 ) |
@@ -132,7 +134,7 @@ dvbpsi_descriptor_t * dvbpsi_GenExtendedEventDr(dvbpsi_extended_event_dr_t * p_d
 
     p += 4;
 
-    for (int i = 0; i < p_decoded->i_entry_count; i++)
+    for (i = 0; i < p_decoded->i_entry_count; i++)
     {
         p[0] = p_decoded->i_item_description_length[i];
         memcpy( &p[1], p_decoded->i_item_description[i], p[0] );
diff --git a/src/descriptors/dr_4f.c b/src/descriptors/dr_4f.c
index ba70790..2e8b8b0 100644
--- a/src/descriptors/dr_4f.c
+++ b/src/descriptors/dr_4f.c
@@ -43,6 +43,7 @@
  * dvbpsi_DecodeTimeShiftedEventDr
  *****************************************************************************/
 dvbpsi_tshifted_ev_dr_t* dvbpsi_DecodeTimeShiftedEventDr(dvbpsi_descriptor_t * p_descriptor) {
+    dvbpsi_tshifted_ev_dr_t * p_decoded;
     /* Check the tag */
     if (p_descriptor->i_tag != 0x4F)
         return NULL;
@@ -56,7 +57,6 @@ dvbpsi_tshifted_ev_dr_t* dvbpsi_DecodeTimeShiftedEventDr(dvbpsi_descriptor_t * p
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_tshifted_ev_dr_t * p_decoded;
     p_decoded = (dvbpsi_tshifted_ev_dr_t*)calloc(1, sizeof(dvbpsi_tshifted_ev_dr_t));
     if (!p_decoded)
         return NULL;
diff --git a/src/descriptors/dr_50.c b/src/descriptors/dr_50.c
index a2e491c..a5b7b6b 100644
--- a/src/descriptors/dr_50.c
+++ b/src/descriptors/dr_50.c
@@ -44,6 +44,7 @@
  *****************************************************************************/
 dvbpsi_component_dr_t* dvbpsi_DecodeComponentDr(dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_component_dr_t * p_decoded;
     /* Check the tag */
     if (p_descriptor->i_tag != 0x50)
         return NULL;
@@ -57,7 +58,6 @@ dvbpsi_component_dr_t* dvbpsi_DecodeComponentDr(dvbpsi_descriptor_t * p_descript
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_component_dr_t * p_decoded;
     p_decoded = (dvbpsi_component_dr_t*)calloc(1, sizeof(dvbpsi_component_dr_t));
     if (!p_decoded)
         return NULL;
diff --git a/src/descriptors/dr_53.c b/src/descriptors/dr_53.c
index 60094da..1bfa47b 100644
--- a/src/descriptors/dr_53.c
+++ b/src/descriptors/dr_53.c
@@ -45,6 +45,7 @@
 dvbpsi_ca_identifier_dr_t * dvbpsi_DecodeCAIdentifierDr(dvbpsi_descriptor_t *p_descriptor)
 {
     dvbpsi_ca_identifier_dr_t * p_decoded;
+	int i_number, i;
 
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x53))
@@ -62,12 +63,12 @@ dvbpsi_ca_identifier_dr_t * dvbpsi_DecodeCAIdentifierDr(dvbpsi_descriptor_t *p_d
     if (!p_decoded)
         return NULL;
 
-    int i_number = p_descriptor->i_length / 2;
+    i_number = p_descriptor->i_length / 2;
     if (i_number > DVBPSI_CA_SYSTEM_ID_DR_MAX)
         i_number = DVBPSI_CA_SYSTEM_ID_DR_MAX;
     p_decoded->i_number = i_number;
 
-    for (int i = 0; i < i_number; i++)
+    for (i = 0; i < i_number; i++)
     {
         /* TODO: decode CA system identifier values */
         p_decoded->p_system[i].i_ca_system_id = p_descriptor->p_data[2 * i];
@@ -85,16 +86,18 @@ dvbpsi_ca_identifier_dr_t * dvbpsi_DecodeCAIdentifierDr(dvbpsi_descriptor_t *p_d
 dvbpsi_descriptor_t * dvbpsi_GenCAIdentifierDr(dvbpsi_ca_identifier_dr_t *p_decoded,
                                                bool b_duplicate)
 {
+	dvbpsi_descriptor_t* p_descriptor;
+	int i;
     if (p_decoded->i_number > DVBPSI_CA_SYSTEM_ID_DR_MAX)
         p_decoded->i_number = DVBPSI_CA_SYSTEM_ID_DR_MAX;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor = dvbpsi_NewDescriptor(0x53, p_decoded->i_number * 2, NULL);
+    p_descriptor = dvbpsi_NewDescriptor(0x53, p_decoded->i_number * 2, NULL);
     if (!p_descriptor)
         return NULL;
 
     /* Encode data */
-    for (int i = 0; i < p_decoded->i_number; i++ )
+    for (i = 0; i < p_decoded->i_number; i++ )
     {
         p_descriptor->p_data[2 * i] = p_decoded->p_system[i].i_ca_system_id >> 8;
         p_descriptor->p_data[2 * i + 1] = p_decoded->p_system[i].i_ca_system_id;
diff --git a/src/descriptors/dr_54.c b/src/descriptors/dr_54.c
index b385561..6fbeb2f 100644
--- a/src/descriptors/dr_54.c
+++ b/src/descriptors/dr_54.c
@@ -45,6 +45,8 @@
 dvbpsi_content_dr_t * dvbpsi_DecodeContentDr(
                                         dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_content_dr_t * p_decoded;
+	int i_contents_number, i;
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x54))
         return NULL;
@@ -58,17 +60,16 @@ dvbpsi_content_dr_t * dvbpsi_DecodeContentDr(
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_content_dr_t * p_decoded;
     p_decoded = (dvbpsi_content_dr_t*)malloc(sizeof(dvbpsi_content_dr_t));
     if (!p_decoded)
         return NULL;
 
-    int i_contents_number = p_descriptor->i_length / 2;
+    i_contents_number = p_descriptor->i_length / 2;
     if (i_contents_number > DVBPSI_CONTENT_DR_MAX)
         i_contents_number = DVBPSI_CONTENT_DR_MAX;
     p_decoded->i_contents_number = i_contents_number;
 
-    for (int i = 0; i < i_contents_number; i++)
+    for (i = 0; i < i_contents_number; i++)
     {
         p_decoded->p_content[i].i_type = p_descriptor->p_data[2 * i];
         p_decoded->p_content[i].i_user_byte = p_descriptor->p_data[2 * i + 1];
@@ -87,18 +88,20 @@ dvbpsi_descriptor_t * dvbpsi_GenContentDr(
                                         dvbpsi_content_dr_t * p_decoded,
                                         bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
+	int i;
     if (p_decoded->i_contents_number > DVBPSI_CONTENT_DR_MAX)
         p_decoded->i_contents_number = DVBPSI_CONTENT_DR_MAX;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x54, p_decoded->i_contents_number * 2 , NULL);
 
     if (!p_descriptor)
         return NULL;
 
     /* Encode data */
-    for (int i = 0; i < p_decoded->i_contents_number; i++ )
+    for (i = 0; i < p_decoded->i_contents_number; i++ )
     {
         p_descriptor->p_data[8 * i] = p_decoded->p_content[i].i_type;
         p_descriptor->p_data[8 * i + 1] = p_decoded->p_content[i].i_user_byte;
diff --git a/src/descriptors/dr_55.c b/src/descriptors/dr_55.c
index 3089cdd..9b35768 100644
--- a/src/descriptors/dr_55.c
+++ b/src/descriptors/dr_55.c
@@ -47,6 +47,8 @@
 dvbpsi_parental_rating_dr_t * dvbpsi_DecodeParentalRatingDr(
                                         dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_parental_rating_dr_t * p_decoded;
+	int i_ratings_number, i;
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x55))
         return NULL;
@@ -60,17 +62,16 @@ dvbpsi_parental_rating_dr_t * dvbpsi_DecodeParentalRatingDr(
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_parental_rating_dr_t * p_decoded;
     p_decoded = (dvbpsi_parental_rating_dr_t*)malloc(sizeof(dvbpsi_parental_rating_dr_t));
     if (!p_decoded)
         return NULL;
 
-    int i_ratings_number = p_descriptor->i_length / 4;
+    i_ratings_number = p_descriptor->i_length / 4;
     if (i_ratings_number > DVBPSI_PARENTAL_RATING_DR_MAX)
         i_ratings_number = DVBPSI_PARENTAL_RATING_DR_MAX;
     p_decoded->i_ratings_number = i_ratings_number;
 
-    for (int i = 0; i < i_ratings_number; i++)
+    for (i = 0; i < i_ratings_number; i++)
     {
         p_decoded->p_parental_rating[i].i_country_code =
                 ((uint32_t)p_descriptor->p_data[4 * i] << 16)
@@ -93,18 +94,20 @@ dvbpsi_descriptor_t * dvbpsi_GenParentalRatingDr(
                                         dvbpsi_parental_rating_dr_t * p_decoded,
                                         bool b_duplicate)
 {    
+    dvbpsi_descriptor_t * p_descriptor;
+	int i;
     if (p_decoded->i_ratings_number > DVBPSI_PARENTAL_RATING_DR_MAX)
         p_decoded->i_ratings_number = DVBPSI_PARENTAL_RATING_DR_MAX;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x55, p_decoded->i_ratings_number * 4 , NULL);
 
     if (!p_descriptor)
         return NULL;
 
     /* Encode data */
-    for (int i = 0; i < p_decoded->i_ratings_number; i++ )
+    for (i = 0; i < p_decoded->i_ratings_number; i++ )
     {
         p_descriptor->p_data[8 * i] =
                 p_decoded->p_parental_rating[i].i_country_code >> 16;
diff --git a/src/descriptors/dr_56.c b/src/descriptors/dr_56.c
index a0edb1f..c42e778 100644
--- a/src/descriptors/dr_56.c
+++ b/src/descriptors/dr_56.c
@@ -46,6 +46,8 @@
 dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr(
                                         dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_teletext_dr_t * p_decoded;
+    int i_pages_number, i;
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x56) &&
             !dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x46))
@@ -63,18 +65,16 @@ dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr(
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_teletext_dr_t * p_decoded;
     p_decoded = (dvbpsi_teletext_dr_t*)malloc(sizeof(dvbpsi_teletext_dr_t));
     if (!p_decoded)
         return NULL;
 
-    int i_pages_number;
     i_pages_number = p_descriptor->i_length / 5;
     if (i_pages_number > DVBPSI_TELETEXT_DR_MAX)
         i_pages_number = DVBPSI_TELETEXT_DR_MAX;
     p_decoded->i_pages_number = i_pages_number;
 
-    for (int i = 0; i < i_pages_number; i++)
+    for (i = 0; i < i_pages_number; i++)
     {
         memcpy(p_decoded->p_pages[i].i_iso6392_language_code,
                p_descriptor->p_data + 5 * i, 3);
@@ -100,17 +100,19 @@ dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr(
 dvbpsi_descriptor_t * dvbpsi_GenTeletextDr(dvbpsi_teletext_dr_t * p_decoded,
                                            bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
+	int i;
     if (p_decoded->i_pages_number > DVBPSI_TELETEXT_DR_MAX)
         p_decoded->i_pages_number = DVBPSI_TELETEXT_DR_MAX;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x56, p_decoded->i_pages_number * 8 , NULL);
     if (!p_descriptor)
         return NULL;
 
     /* Encode data */
-    for (int i = 0; i < p_decoded->i_pages_number; i++ )
+    for (i = 0; i < p_decoded->i_pages_number; i++ )
     {
         memcpy( p_descriptor->p_data + 8 * i,
                 p_decoded->p_pages[i].i_iso6392_language_code,
diff --git a/src/descriptors/dr_58.c b/src/descriptors/dr_58.c
index cc52630..cb1fc46 100644
--- a/src/descriptors/dr_58.c
+++ b/src/descriptors/dr_58.c
@@ -106,23 +106,25 @@ dvbpsi_descriptor_t * dvbpsi_GenLocalTimeOffsetDr(
                                         dvbpsi_local_time_offset_dr_t * p_decoded,
                                         bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
+	uint8_t i_num;
+    dvbpsi_local_time_offset_t * p_current;
+    uint8_t * p_data;
+
     if (p_decoded->i_local_time_offsets_number > DVBPSI_LOCAL_TIME_OFFSET_DR_MAX)
         p_decoded->i_local_time_offsets_number = DVBPSI_LOCAL_TIME_OFFSET_DR_MAX;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x58, p_decoded->i_local_time_offsets_number * 13, NULL);
     if (!p_descriptor)
         return NULL;
 
     /* Encode data */
-    dvbpsi_local_time_offset_t * p_current;
-    uint8_t * p_data;
-
     p_current = p_decoded->p_local_time_offset;
     p_data = p_descriptor->p_data;
 
-    for (uint8_t i_num = 0; i_num < p_decoded->i_local_time_offsets_number; i_num++)
+    for (i_num = 0; i_num < p_decoded->i_local_time_offsets_number; i_num++)
     {
         memcpy(p_data, p_current->i_country_code, 3);
         p_data[3]  =   ((p_current->i_country_region_id & 0x3f) << 2)
diff --git a/src/descriptors/dr_59.c b/src/descriptors/dr_59.c
index 9261db8..952077f 100644
--- a/src/descriptors/dr_59.c
+++ b/src/descriptors/dr_59.c
@@ -48,7 +48,7 @@
 dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr(
                                         dvbpsi_descriptor_t * p_descriptor)
 {
-    int i_subtitles_number;
+    int i_subtitles_number, i;
     dvbpsi_subtitling_dr_t * p_decoded;
 
     /* Check the tag */
@@ -76,7 +76,7 @@ dvbpsi_subtitling_dr_t * dvbpsi_DecodeSubtitlingDr(
         i_subtitles_number = DVBPSI_SUBTITLING_DR_MAX;
     p_decoded->i_subtitles_number = i_subtitles_number;
 
-    for (int i = 0; i < i_subtitles_number; i++)
+    for (i = 0; i < i_subtitles_number; i++)
     {
         memcpy(p_decoded->p_subtitle[i].i_iso6392_language_code,
                p_descriptor->p_data + 8 * i, 3);
@@ -106,17 +106,19 @@ dvbpsi_descriptor_t * dvbpsi_GenSubtitlingDr(
                                         dvbpsi_subtitling_dr_t * p_decoded,
                                         bool b_duplicate)
 {
+    dvbpsi_descriptor_t * p_descriptor;
+	int i;
     if (p_decoded->i_subtitles_number > DVBPSI_SUBTITLING_DR_MAX)
         p_decoded->i_subtitles_number = DVBPSI_SUBTITLING_DR_MAX;
 
     /* Create the descriptor */
-    dvbpsi_descriptor_t * p_descriptor =
+    p_descriptor =
             dvbpsi_NewDescriptor(0x59, p_decoded->i_subtitles_number * 8 , NULL);
     if (!p_descriptor)
         return NULL;
 
     /* Encode data */
-    for (int i = 0; i < p_decoded->i_subtitles_number; i++ )
+    for (i = 0; i < p_decoded->i_subtitles_number; i++ )
     {
         memcpy( p_descriptor->p_data + 8 * i,
                 p_decoded->p_subtitle[i].i_iso6392_language_code,
diff --git a/src/descriptors/dr_5a.c b/src/descriptors/dr_5a.c
index cbd3016..87038ff 100644
--- a/src/descriptors/dr_5a.c
+++ b/src/descriptors/dr_5a.c
@@ -47,6 +47,7 @@
 dvbpsi_terr_deliv_sys_dr_t * dvbpsi_DecodeTerrDelivSysDr(
                                         dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_terr_deliv_sys_dr_t * p_decoded;
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x5a))
         return NULL;
@@ -56,7 +57,6 @@ dvbpsi_terr_deliv_sys_dr_t * dvbpsi_DecodeTerrDelivSysDr(
         return p_descriptor->p_decoded;
 
     /* Allocate memory */
-    dvbpsi_terr_deliv_sys_dr_t * p_decoded;
     p_decoded = (dvbpsi_terr_deliv_sys_dr_t*)malloc(sizeof(dvbpsi_terr_deliv_sys_dr_t));
     if (!p_decoded)
         return NULL;
diff --git a/src/descriptors/dr_76.c b/src/descriptors/dr_76.c
index b32ee31..7cec2ba 100644
--- a/src/descriptors/dr_76.c
+++ b/src/descriptors/dr_76.c
@@ -77,10 +77,10 @@ dvbpsi_content_id_dr_t *dvbpsi_DecodeContentIdDr(dvbpsi_descriptor_t *p_descript
         if (entry->i_location == CRID_LOCATION_DESCRIPTOR)
         {
             uint8_t len = p_descriptor->p_data[byte];
+            unsigned int i, last;
             if (len > 253)
                 len = 253;
 
-            unsigned int i;
             byte ++;
             for (i = 0; i < len; i ++)
             {
@@ -88,7 +88,7 @@ dvbpsi_content_id_dr_t *dvbpsi_DecodeContentIdDr(dvbpsi_descriptor_t *p_descript
             }
             byte += len;
             /* Properly terminate the string */
-            unsigned int last = (i < len) ? i : len - 1U;
+            last = (i < len) ? i : len - 1U;
             entry->value.path[last] = 0;
         }
         else if (entry->i_location == CRID_LOCATION_CIT)
diff --git a/src/descriptors/dr_7c.c b/src/descriptors/dr_7c.c
index f51acb4..5f2de82 100644
--- a/src/descriptors/dr_7c.c
+++ b/src/descriptors/dr_7c.c
@@ -109,8 +109,9 @@ static struct dvbpsi_aac_profile_and_level_table_s aac_profile_and_level_table[]
 static dvbpsi_aac_profile_and_level_t dvbpsi_aac_profile_and_level_lookup(const uint8_t value)
 {
     dvbpsi_aac_profile_and_level_t profile_and_level = DVBPSI_AAC_PROFILE_RESERVED;
+	unsigned int i;
 
-    for (unsigned int i = 0; i < ARRAY_SIZE(aac_profile_and_level_table); i++)
+    for (i = 0; i < ARRAY_SIZE(aac_profile_and_level_table); i++)
     {
         if (aac_profile_and_level_table[i].hex == value)
             profile_and_level = aac_profile_and_level_table[i].profile_and_level;
@@ -127,7 +128,8 @@ static uint8_t dvbpsi_aac_profile_and_level_to_hex(const dvbpsi_aac_profile_and_
         value = 0x56; /* FIXME: levels 0x56..0x57 and 0x5C..0xFF are mapped onto 0x56 here */
     else
     {
-        for (unsigned int i = 0; i < ARRAY_SIZE(aac_profile_and_level_table); i++)
+		unsigned int i;
+        for (i = 0; i < ARRAY_SIZE(aac_profile_and_level_table); i++)
         {
             if (aac_profile_and_level_table[i].profile_and_level == profile_and_level)
                 value = aac_profile_and_level_table[i].hex;
@@ -179,7 +181,8 @@ static dvbpsi_aac_type_t dvbpsi_aac_type_lookup(const uint8_t value)
         type = DVBPSI_AAC_RESERVED5;
     else
     {
-        for (unsigned int i = 0; i < ARRAY_SIZE(aac_type_table); i++)
+		unsigned int i;
+        for (i = 0; i < ARRAY_SIZE(aac_type_table); i++)
         {
             if (aac_type_table[i].hex == value)
                 type = aac_type_table[i].type;
@@ -191,6 +194,7 @@ static dvbpsi_aac_type_t dvbpsi_aac_type_lookup(const uint8_t value)
 static uint8_t dvbpsi_aac_type_to_hex(const dvbpsi_aac_type_t type)
 {
     uint8_t value = 0;
+	unsigned int i;
 
     if (type == DVBPSI_AAC_RESERVED3)
         value = 0x06; /* FIXME: 0x06..0x3F */
@@ -202,7 +206,7 @@ static uint8_t dvbpsi_aac_type_to_hex(const dvbpsi_aac_type_t type)
         value = 0xFF;
     else
     {
-        for (unsigned int i = 0; i < ARRAY_SIZE(aac_type_table); i++)
+        for (i = 0; i < ARRAY_SIZE(aac_type_table); i++)
         {
             if (aac_type_table[i].type == type)
                 value = aac_type_table[i].hex;
@@ -216,6 +220,7 @@ static uint8_t dvbpsi_aac_type_to_hex(const dvbpsi_aac_type_t type)
  *****************************************************************************/
 dvbpsi_aac_dr_t *dvbpsi_DecodeAACDr(dvbpsi_descriptor_t *p_descriptor)
 {
+    dvbpsi_aac_dr_t *p_decoded;
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x7c))
         return NULL;
@@ -228,7 +233,6 @@ dvbpsi_aac_dr_t *dvbpsi_DecodeAACDr(dvbpsi_descriptor_t *p_descriptor)
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_aac_dr_t *p_decoded;
     p_decoded = (dvbpsi_aac_dr_t*)calloc(1, sizeof(dvbpsi_aac_dr_t));
     if (!p_decoded)
         return NULL;
@@ -247,6 +251,8 @@ dvbpsi_aac_dr_t *dvbpsi_DecodeAACDr(dvbpsi_descriptor_t *p_descriptor)
     {
         uint8_t i_info_length = p_descriptor->i_length - (p_decoded->b_type ? 3 : 2);
         dvbpsi_aac_dr_t *p_tmp = realloc(p_decoded, sizeof(dvbpsi_aac_dr_t) + i_info_length);
+        uint8_t i_data;
+        uint8_t *p;
         if (!p_tmp)
         {
             free(p_decoded);
@@ -255,8 +261,8 @@ dvbpsi_aac_dr_t *dvbpsi_DecodeAACDr(dvbpsi_descriptor_t *p_descriptor)
         p_decoded->p_additional_info = ((uint8_t*)p_tmp + sizeof(dvbpsi_aac_dr_t));
         p_decoded->i_additional_info_length = i_info_length;
 
-        uint8_t i_data = p_decoded->b_type ? 3 : 2;
-        uint8_t *p = &p_descriptor->p_data[i_data];
+        i_data = p_decoded->b_type ? 3 : 2;
+        p = &p_descriptor->p_data[i_data];
         memcpy(&p_decoded->p_additional_info, p, i_info_length);
     }
 
diff --git a/src/descriptors/dr_86.c b/src/descriptors/dr_86.c
index 117d58a..9ddb3cf 100644
--- a/src/descriptors/dr_86.c
+++ b/src/descriptors/dr_86.c
@@ -46,6 +46,7 @@ dvbpsi_caption_service_dr_t *dvbpsi_DecodeCaptionServiceDr(dvbpsi_descriptor_t *
 {
     dvbpsi_caption_service_dr_t *p_decoded;
     uint8_t * buf = p_descriptor->p_data;
+	int i;
 
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x86))
@@ -68,7 +69,7 @@ dvbpsi_caption_service_dr_t *dvbpsi_DecodeCaptionServiceDr(dvbpsi_descriptor_t *
     p_decoded->i_number_of_services = 0x1f & buf[0];
     buf++;
 
-    for (int i = 0; i < p_decoded->i_number_of_services; i++)
+    for (i = 0; i < p_decoded->i_number_of_services; i++)
     {
         dvbpsi_caption_service_t * p_service = &p_decoded->services[i];
 
diff --git a/src/descriptors/dr_8a.c b/src/descriptors/dr_8a.c
index 899640e..7e059af 100644
--- a/src/descriptors/dr_8a.c
+++ b/src/descriptors/dr_8a.c
@@ -45,6 +45,7 @@
  *****************************************************************************/
 dvbpsi_cuei_dr_t * dvbpsi_DecodeCUEIDr(dvbpsi_descriptor_t * p_descriptor)
 {
+    dvbpsi_cuei_dr_t *p_decoded;
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0x8a))
         return NULL;
@@ -57,7 +58,6 @@ dvbpsi_cuei_dr_t * dvbpsi_DecodeCUEIDr(dvbpsi_descriptor_t * p_descriptor)
         return NULL;
 
     /* Allocate memory */
-    dvbpsi_cuei_dr_t *p_decoded;
     p_decoded = (dvbpsi_cuei_dr_t*)malloc(sizeof(dvbpsi_cuei_dr_t));
     if (!p_decoded)
         return NULL;
diff --git a/src/descriptors/dr_a1.c b/src/descriptors/dr_a1.c
index faeb8a2..a737480 100644
--- a/src/descriptors/dr_a1.c
+++ b/src/descriptors/dr_a1.c
@@ -49,6 +49,7 @@ dvbpsi_DecodeServiceLocationDr (dvbpsi_descriptor_t * p_descriptor)
 {
     dvbpsi_service_location_dr_t *p_decoded;
     uint8_t *buf = p_descriptor->p_data;
+	int i;
 
     /* Check the tag */
     if (!dvbpsi_CanDecodeAsDescriptor(p_descriptor, 0xa1))
@@ -77,7 +78,7 @@ dvbpsi_DecodeServiceLocationDr (dvbpsi_descriptor_t * p_descriptor)
 
     buf += 3;
 
-    for (int i = 0; i < p_decoded->i_number_elements; i++)
+    for (i = 0; i < p_decoded->i_number_elements; i++)
     {
         dvbpsi_service_location_element_t *p_element = &p_decoded->elements[i];
 
diff --git a/src/dvbpsi.c b/src/dvbpsi.c
index 89d4932..6c0c903 100644
--- a/src/dvbpsi.c
+++ b/src/dvbpsi.c
@@ -79,9 +79,10 @@ void dvbpsi_delete(dvbpsi_t *p_dvbpsi)
 void *dvbpsi_decoder_new(dvbpsi_callback_gather_t pf_gather,
     const int i_section_max_size, const bool b_discontinuity, const size_t psi_size)
 {
+	dvbpsi_decoder_t* p_decoder;
     assert(psi_size >= sizeof(dvbpsi_decoder_t));
 
-    dvbpsi_decoder_t *p_decoder = (dvbpsi_decoder_t *) calloc(1, psi_size);
+    p_decoder = (dvbpsi_decoder_t *) calloc(1, psi_size);
     if (p_decoder == NULL)
         return NULL;
 
@@ -122,12 +123,14 @@ void dvbpsi_decoder_reset(dvbpsi_decoder_t* p_decoder, const bool b_force)
  *****************************************************************************/
 bool dvbpsi_decoder_psi_sections_completed(dvbpsi_decoder_t* p_decoder)
 {
-    assert(p_decoder);
 
     bool b_complete = false;
 
-    dvbpsi_psi_section_t *p = p_decoder->p_sections;
+    dvbpsi_psi_section_t *p;
     unsigned int prev_nr = 0;
+
+    assert(p_decoder);
+    p = p_decoder->p_sections;
     while (p)
     {
         assert(prev_nr < 256);
@@ -147,6 +150,10 @@ bool dvbpsi_decoder_psi_sections_completed(dvbpsi_decoder_t* p_decoder)
  *****************************************************************************/
 bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_section_t *p_section)
 {
+    dvbpsi_psi_section_t *p_prev = NULL;
+    bool b_overwrite = false;
+    dvbpsi_psi_section_t *p;
+
     assert(p_decoder);
     assert(p_section);
     assert(p_section->p_next == NULL);
@@ -160,9 +167,7 @@ bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_sect
     }
 
     /* Insert in right place */
-    dvbpsi_psi_section_t *p = p_decoder->p_sections;
-    dvbpsi_psi_section_t *p_prev = NULL;
-    bool b_overwrite = false;
+    p = p_decoder->p_sections;
 
     while (p)
     {
@@ -262,6 +267,7 @@ bool dvbpsi_packet_push(dvbpsi_t *p_dvbpsi, uint8_t* p_data)
                                              section is handled */
     int i_available;                      /* Byte count available in the
                                              packet */
+	bool b_first;
 
     dvbpsi_decoder_t *p_decoder = p_dvbpsi->p_decoder;
     assert(p_decoder);
@@ -274,7 +280,7 @@ bool dvbpsi_packet_push(dvbpsi_t *p_dvbpsi, uint8_t* p_data)
     }
 
     /* Continuity check */
-    bool b_first = (p_decoder->i_continuity_counter == DVBPSI_INVALID_CC);
+    b_first = (p_decoder->i_continuity_counter == DVBPSI_INVALID_CC);
     if (b_first)
         p_decoder->i_continuity_counter = p_data[3] & 0xf;
     else
@@ -521,10 +527,11 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
         (level <= dvbpsi->i_msg_level))
     {
         va_list ap;
-        va_start(ap, fmt);
         char *msg = NULL;
+		int err;
+        va_start(ap, fmt);
 #if defined(_GNU_SOURCE)
-        int err = vasprintf(&msg, fmt, ap);
+        err = vasprintf(&msg, fmt, ap);
 #else
         msg = malloc(DVBPSI_MSG_SIZE);
         if (msg == NULL) {
@@ -536,7 +543,7 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
             free(msg);
             return;
         }
-        int err = vsnprintf(&msg, DVBPSI_MSG_SIZE, fmt, ap);
+        err = vsnprintf(&msg, DVBPSI_MSG_SIZE, fmt, ap);
 #endif
         va_end(ap);
         if (err > DVBPSI_MSG_NONE) {
@@ -553,14 +560,15 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
 #       define DVBPSI_MSG_COMMON(level)                         \
     do {                                                        \
         va_list ap;                                             \
-        va_start(ap, fmt);                                      \
         char *tmp = NULL;                                       \
-        int err = vasprintf(&tmp, fmt, ap);                     \
+		int err; \
+        char *msg = NULL;                                       \
+        va_start(ap, fmt);                                      \
+        err = vasprintf(&tmp, fmt, ap);                     \
         if (err < 0) {                                          \
             va_end(ap);                                         \
             return;                                             \
         }                                                       \
-        char *msg = NULL;                                       \
         if (asprintf(&msg, DVBPSI_MSG_FORMAT, src, tmp) < 0) {  \
             va_end(ap);                                         \
             free(tmp);                                          \
@@ -578,8 +586,9 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
 #       define DVBPSI_MSG_COMMON                                \
     do {                                                        \
         va_list ap;                                             \
-        va_start(ap, fmt);                                      \
         char *msg = malloc(DVBPSI_MSG_SIZE);                    \
+		int err; \
+        va_start(ap, fmt);                                      \
         if (msg == NULL) {                                      \
             va_end(ap);                                         \
             return;                                             \
@@ -588,7 +597,7 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
             va_end(ap);                                         \
             return;                                             \
         }                                                       \
-        int err = vsnprintf(&msg, DVBPSI_MSG_SIZE, fmt, ap);    \
+        err = vsnprintf(&msg, DVBPSI_MSG_SIZE, fmt, ap);    \
         va_end(ap);                                             \
         if (err > 0) {                                          \
             if (dvbpsi->pf_message)                             \
diff --git a/src/tables/atsc_eit.c b/src/tables/atsc_eit.c
index b276fd1..eae50bb 100644
--- a/src/tables/atsc_eit.c
+++ b/src/tables/atsc_eit.c
@@ -83,10 +83,13 @@ static void dvbpsi_atsc_DecodeEITSections(dvbpsi_atsc_eit_t* p_eit,
 bool dvbpsi_atsc_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                            dvbpsi_atsc_eit_callback pf_callback, void* p_cb_data)
 {
+    dvbpsi_demux_t* p_demux;
+    dvbpsi_atsc_eit_decoder_t* p_eit_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
 
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
     {
@@ -96,13 +99,11 @@ bool dvbpsi_atsc_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
         return false;
     }
 
-    dvbpsi_atsc_eit_decoder_t* p_eit_decoder;
     p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*) dvbpsi_decoder_new(NULL,
                                                     0, true, sizeof(dvbpsi_atsc_eit_decoder_t));
     if (p_eit_decoder == NULL)
         return false;
 
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachEIT,
                                          dvbpsi_atsc_GatherEITSections, DVBPSI_DECODER(p_eit_decoder));
     if (p_subdec == NULL)
@@ -129,11 +130,13 @@ bool dvbpsi_atsc_AttachEIT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
  *****************************************************************************/
 void dvbpsi_atsc_DetachEIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_demux_subdec_t* p_subdec;
+    dvbpsi_atsc_eit_decoder_t* p_eit_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
-    dvbpsi_demux_subdec_t* p_subdec;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if (p_subdec == NULL)
     {
@@ -144,7 +147,6 @@ void dvbpsi_atsc_DetachEIT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_e
         return;
     }
 
-    dvbpsi_atsc_eit_decoder_t* p_eit_decoder;
     p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*)p_subdec->p_decoder;
     if (!p_eit_decoder)
         return;
@@ -383,6 +385,8 @@ static void dvbpsi_atsc_GatherEITSections(dvbpsi_t * p_dvbpsi,
                                           dvbpsi_decoder_t *p_decoder,
                                           dvbpsi_psi_section_t * p_section)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_atsc_eit_decoder_t *p_eit_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
@@ -393,8 +397,8 @@ static void dvbpsi_atsc_GatherEITSections(dvbpsi_t * p_dvbpsi,
     }
 
     /* We have a valid EIT section */
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
-    dvbpsi_atsc_eit_decoder_t *p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*)p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_eit_decoder = (dvbpsi_atsc_eit_decoder_t*)p_decoder;
     if (!p_eit_decoder)
     {
         dvbpsi_error(p_dvbpsi, "ATSC EIT decoder", "No decoder specified");
diff --git a/src/tables/atsc_ett.c b/src/tables/atsc_ett.c
index 9b4358b..d27619e 100644
--- a/src/tables/atsc_ett.c
+++ b/src/tables/atsc_ett.c
@@ -86,10 +86,13 @@ static void dvbpsi_atsc_DecodeETTSections(dvbpsi_atsc_ett_t* p_ett,
 bool dvbpsi_atsc_AttachETT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                           dvbpsi_atsc_ett_callback pf_callback, void* p_cb_data)
 {
+    dvbpsi_demux_t* p_demux;
+    dvbpsi_atsc_ett_decoder_t* p_ett_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
 
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
     {
@@ -99,14 +102,12 @@ bool dvbpsi_atsc_AttachETT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_e
         return false;
     }
 
-    dvbpsi_atsc_ett_decoder_t* p_ett_decoder;
     p_ett_decoder = (dvbpsi_atsc_ett_decoder_t*) dvbpsi_decoder_new(NULL,
                                                   0, true, sizeof(dvbpsi_atsc_ett_decoder_t));
     if (p_ett_decoder == NULL)
         return false;
 
     /* PSI decoder configuration */
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachETT,
                                          dvbpsi_atsc_GatherETTSections, DVBPSI_DECODER(p_ett_decoder));
     if (p_subdec == NULL)
@@ -133,12 +134,14 @@ bool dvbpsi_atsc_AttachETT(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_e
  *****************************************************************************/
 void dvbpsi_atsc_DetachETT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_demux_subdec_t* p_subdec;
+    dvbpsi_atsc_ett_decoder_t* p_ett_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
 
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if (p_subdec == NULL)
     {
@@ -149,7 +152,6 @@ void dvbpsi_atsc_DetachETT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
         return;
     }
 
-    dvbpsi_atsc_ett_decoder_t* p_ett_decoder;
     p_ett_decoder = (dvbpsi_atsc_ett_decoder_t*)p_subdec->p_decoder;
     if (!p_ett_decoder)
         return;
@@ -321,6 +323,8 @@ static void dvbpsi_atsc_GatherETTSections(dvbpsi_t* p_dvbpsi,
                                           dvbpsi_decoder_t *p_decoder,
                                           dvbpsi_psi_section_t* p_section)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_atsc_ett_decoder_t* p_ett_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
@@ -331,8 +335,8 @@ static void dvbpsi_atsc_GatherETTSections(dvbpsi_t* p_dvbpsi,
     }
 
     /* We have a valid ETT section */
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
-    dvbpsi_atsc_ett_decoder_t* p_ett_decoder = (dvbpsi_atsc_ett_decoder_t*)p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_ett_decoder = (dvbpsi_atsc_ett_decoder_t*)p_decoder;
     if (!p_ett_decoder)
     {
         dvbpsi_error(p_dvbpsi, "ATSC ETT decoder", "No decoder specified");
diff --git a/src/tables/atsc_mgt.c b/src/tables/atsc_mgt.c
index 3537274..2f6f613 100644
--- a/src/tables/atsc_mgt.c
+++ b/src/tables/atsc_mgt.c
@@ -87,10 +87,13 @@ static void dvbpsi_atsc_DecodeMGTSections(dvbpsi_atsc_mgt_t* p_mgt,
 bool dvbpsi_atsc_AttachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                            dvbpsi_atsc_mgt_callback pf_callback, void* p_cb_data)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_atsc_mgt_decoder_t*  p_mgt_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
 
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
     {
@@ -100,13 +103,11 @@ bool dvbpsi_atsc_AttachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
         return false;
     }
 
-    dvbpsi_atsc_mgt_decoder_t*  p_mgt_decoder;
     p_mgt_decoder = (dvbpsi_atsc_mgt_decoder_t*) dvbpsi_decoder_new(NULL,
                                                   0, true, sizeof(dvbpsi_atsc_mgt_decoder_t));
     if(p_mgt_decoder == NULL)
         return false;
 
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachMGT,
                                          dvbpsi_atsc_GatherMGTSections, DVBPSI_DECODER(p_mgt_decoder));
     if (p_subdec == NULL)
@@ -133,12 +134,14 @@ bool dvbpsi_atsc_AttachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
  *****************************************************************************/
 void dvbpsi_atsc_DetachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_demux_subdec_t* p_subdec;
+    dvbpsi_atsc_mgt_decoder_t* p_mgt_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
 
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if (p_subdec == NULL)
     {
@@ -149,7 +152,6 @@ void dvbpsi_atsc_DetachMGT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
         return;
     }
 
-    dvbpsi_atsc_mgt_decoder_t* p_mgt_decoder;
     p_mgt_decoder = (dvbpsi_atsc_mgt_decoder_t*)p_subdec->p_decoder;
     if (!p_mgt_decoder)
         return;
@@ -406,6 +408,8 @@ static void dvbpsi_atsc_GatherMGTSections(dvbpsi_t * p_dvbpsi,
                               dvbpsi_decoder_t *p_decoder,
                               dvbpsi_psi_section_t * p_section)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_atsc_mgt_decoder_t * p_mgt_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
@@ -416,8 +420,8 @@ static void dvbpsi_atsc_GatherMGTSections(dvbpsi_t * p_dvbpsi,
     }
 
     /* We have a valid MGT section */
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
-    dvbpsi_atsc_mgt_decoder_t * p_mgt_decoder = (dvbpsi_atsc_mgt_decoder_t*)p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_mgt_decoder = (dvbpsi_atsc_mgt_decoder_t*)p_decoder;
     if (!p_mgt_decoder)
     {
         dvbpsi_error(p_dvbpsi, "ATSC MGT decoder", "No decoder specified");
diff --git a/src/tables/atsc_stt.c b/src/tables/atsc_stt.c
index 88340ae..f2b9719 100644
--- a/src/tables/atsc_stt.c
+++ b/src/tables/atsc_stt.c
@@ -73,10 +73,13 @@ static void dvbpsi_atsc_DecodeSTTSections(dvbpsi_atsc_stt_t* p_stt,
 bool dvbpsi_atsc_AttachSTT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                            dvbpsi_atsc_stt_callback pf_stt_callback, void* p_cb_data)
 {
+    dvbpsi_demux_t* p_demux;
+    dvbpsi_atsc_stt_decoder_t*  p_stt_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, 0))
     {
         dvbpsi_error(p_dvbpsi, "ATSC STT decoder",
@@ -85,14 +88,12 @@ bool dvbpsi_atsc_AttachSTT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
         return false;
     }
 
-    dvbpsi_atsc_stt_decoder_t*  p_stt_decoder;
     p_stt_decoder = (dvbpsi_atsc_stt_decoder_t*) dvbpsi_decoder_new(NULL,
                                                   0, true, sizeof(dvbpsi_atsc_stt_decoder_t));
     if (p_stt_decoder == NULL)
         return false;
 
     /* subtable decoder configuration */
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachSTT,
                                          dvbpsi_atsc_GatherSTTSections, DVBPSI_DECODER(p_stt_decoder));
     if (p_subdec == NULL)
@@ -119,13 +120,15 @@ bool dvbpsi_atsc_AttachSTT(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
  *****************************************************************************/
 void dvbpsi_atsc_DetachSTT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_demux_subdec_t* p_subdec;
+    dvbpsi_atsc_stt_decoder_t* p_stt_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
 
     i_extension = 0;
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if (p_subdec == NULL)
     {
@@ -136,7 +139,6 @@ void dvbpsi_atsc_DetachSTT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
         return;
     }
 
-    dvbpsi_atsc_stt_decoder_t* p_stt_decoder;
     p_stt_decoder = (dvbpsi_atsc_stt_decoder_t*)p_subdec->p_decoder;
     if(!p_stt_decoder)
         return;
@@ -311,6 +313,8 @@ static void dvbpsi_atsc_GatherSTTSections(dvbpsi_t *p_dvbpsi,
                                           dvbpsi_decoder_t *p_decoder,
                                           dvbpsi_psi_section_t * p_section)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_atsc_stt_decoder_t *p_stt_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
@@ -321,8 +325,8 @@ static void dvbpsi_atsc_GatherSTTSections(dvbpsi_t *p_dvbpsi,
     }
 
     /* */
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
-    dvbpsi_atsc_stt_decoder_t *p_stt_decoder = (dvbpsi_atsc_stt_decoder_t*)p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_stt_decoder = (dvbpsi_atsc_stt_decoder_t*)p_decoder;
     if (!p_stt_decoder)
     {
         dvbpsi_error(p_dvbpsi, "ATSC STT decoder", "No decoder specified");
diff --git a/src/tables/atsc_vct.c b/src/tables/atsc_vct.c
index 7a4ccf4..c1b515e 100644
--- a/src/tables/atsc_vct.c
+++ b/src/tables/atsc_vct.c
@@ -95,10 +95,13 @@ static void dvbpsi_atsc_DecodeVCTSections(dvbpsi_atsc_vct_t* p_vct,
 bool dvbpsi_atsc_AttachVCT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                           dvbpsi_atsc_vct_callback pf_vct_callback, void* p_cb_data)
 {
+    dvbpsi_demux_t* p_demux;
+    dvbpsi_atsc_vct_decoder_t*  p_vct_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
 
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
     {
@@ -109,14 +112,12 @@ bool dvbpsi_atsc_AttachVCT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
         return false;
     }
 
-    dvbpsi_atsc_vct_decoder_t*  p_vct_decoder;
     p_vct_decoder = (dvbpsi_atsc_vct_decoder_t*) dvbpsi_decoder_new(NULL,
                                                   0, true, sizeof(dvbpsi_atsc_vct_decoder_t));
     if (p_vct_decoder == NULL)
         return false;
 
     /* subtable decoder configuration */
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_atsc_DetachVCT,
                                          dvbpsi_atsc_GatherVCTSections, DVBPSI_DECODER(p_vct_decoder));
     if (p_subdec == NULL)
@@ -143,12 +144,14 @@ bool dvbpsi_atsc_AttachVCT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
  *****************************************************************************/
 void dvbpsi_atsc_DetachVCT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_demux_subdec_t* p_subdec;
+    dvbpsi_atsc_vct_decoder_t* p_vct_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
 
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if(p_subdec == NULL)
     {
@@ -159,7 +162,6 @@ void dvbpsi_atsc_DetachVCT(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_ex
         return;
     }
 
-    dvbpsi_atsc_vct_decoder_t* p_vct_decoder;
     p_vct_decoder = (dvbpsi_atsc_vct_decoder_t*)p_subdec->p_decoder;
     if (!p_vct_decoder)
         return;
@@ -446,13 +448,15 @@ static void dvbpsi_atsc_GatherVCTSections(dvbpsi_t *p_dvbpsi,
                                           dvbpsi_decoder_t *p_decoder,
                                           dvbpsi_psi_section_t *p_section)
 {
-    assert(p_dvbpsi);
-    assert(p_dvbpsi->p_decoder);
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_atsc_vct_decoder_t *p_vct_decoder;
 
-    const uint8_t i_table_id = (p_section->i_table_id == 0xC8 ||
+	const uint8_t i_table_id = (p_section->i_table_id == 0xC8 ||
                                 p_section->i_table_id == 0xC9) ?
                                 p_section->i_table_id : 0xC8;
 
+    assert(p_dvbpsi);
+    assert(p_dvbpsi->p_decoder);
     if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, i_table_id, "ATSC VCT decoder"))
     {
         dvbpsi_DeletePSISections(p_section);
@@ -460,8 +464,8 @@ static void dvbpsi_atsc_GatherVCTSections(dvbpsi_t *p_dvbpsi,
     }
 
     /* */
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
-    dvbpsi_atsc_vct_decoder_t *p_vct_decoder = (dvbpsi_atsc_vct_decoder_t*)p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_vct_decoder = (dvbpsi_atsc_vct_decoder_t*)p_decoder;
 
     /* TS discontinuity check */
     if (p_demux->b_discontinuity)
diff --git a/src/tables/bat.c b/src/tables/bat.c
index f4171f8..e55b3ba 100644
--- a/src/tables/bat.c
+++ b/src/tables/bat.c
@@ -58,10 +58,13 @@
 bool dvbpsi_bat_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
           uint16_t i_extension, dvbpsi_bat_callback pf_callback, void* p_cb_data)
 {
+    dvbpsi_demux_t* p_demux;
+    dvbpsi_bat_decoder_t*  p_bat_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
     {
         dvbpsi_error(p_dvbpsi, "BAT decoder",
@@ -71,14 +74,12 @@ bool dvbpsi_bat_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
         return false;
     }
 
-    dvbpsi_bat_decoder_t*  p_bat_decoder;
     p_bat_decoder = (dvbpsi_bat_decoder_t*) dvbpsi_decoder_new(NULL,
                                              0, true, sizeof(dvbpsi_bat_decoder_t));
     if (p_bat_decoder == NULL)
         return false;
 
     /* subtable decoder configuration */
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_bat_detach,
                                          dvbpsi_bat_sections_gather, DVBPSI_DECODER(p_bat_decoder));
     if (p_subdec == NULL)
@@ -105,12 +106,14 @@ bool dvbpsi_bat_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
  *****************************************************************************/
 void dvbpsi_bat_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_bat_decoder_t* p_bat_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
 
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if (p_subdec == NULL)
     {
@@ -121,7 +124,6 @@ void dvbpsi_bat_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
         return;
     }
 
-    dvbpsi_bat_decoder_t* p_bat_decoder;
     p_bat_decoder = (dvbpsi_bat_decoder_t*)p_subdec->p_decoder;
     if (p_bat_decoder->p_building_bat)
         dvbpsi_bat_delete(p_bat_decoder->p_building_bat);
diff --git a/src/tables/cat.c b/src/tables/cat.c
index 385c50d..1539ffc 100644
--- a/src/tables/cat.c
+++ b/src/tables/cat.c
@@ -57,10 +57,10 @@
 bool dvbpsi_cat_attach(dvbpsi_t *p_dvbpsi, dvbpsi_cat_callback pf_callback,
                       void* p_cb_data)
 {
+    dvbpsi_cat_decoder_t* p_cat_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder == NULL);
 
-    dvbpsi_cat_decoder_t* p_cat_decoder;
     p_cat_decoder = (dvbpsi_cat_decoder_t*) dvbpsi_decoder_new(&dvbpsi_cat_sections_gather,
                                                 1024, true, sizeof(dvbpsi_cat_decoder_t));
     if (p_cat_decoder == NULL)
@@ -82,11 +82,11 @@ bool dvbpsi_cat_attach(dvbpsi_t *p_dvbpsi, dvbpsi_cat_callback pf_callback,
  *****************************************************************************/
 void dvbpsi_cat_detach(dvbpsi_t *p_dvbpsi)
 {
+    dvbpsi_cat_decoder_t* p_cat_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_cat_decoder_t* p_cat_decoder
-                        = (dvbpsi_cat_decoder_t*)p_dvbpsi->p_decoder;
+    p_cat_decoder = (dvbpsi_cat_decoder_t*)p_dvbpsi->p_decoder;
     if (p_cat_decoder->p_building_cat)
         dvbpsi_cat_delete(p_cat_decoder->p_building_cat);
     p_cat_decoder->p_building_cat = NULL;
@@ -188,9 +188,9 @@ static void dvbpsi_ReInitCAT(dvbpsi_cat_decoder_t* p_decoder, const bool b_force
 static bool dvbpsi_CheckCAT(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section)
 {
     bool b_reinit = false;
+    dvbpsi_cat_decoder_t* p_cat_decoder;
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_cat_decoder_t* p_cat_decoder;
     p_cat_decoder = (dvbpsi_cat_decoder_t *)p_dvbpsi->p_decoder;
 
     /* Perform a few sanity checks */
@@ -259,6 +259,7 @@ static bool dvbpsi_AddSectionCAT(dvbpsi_t *p_dvbpsi, dvbpsi_cat_decoder_t *p_dec
 void dvbpsi_cat_sections_gather(dvbpsi_t *p_dvbpsi,
                               dvbpsi_psi_section_t* p_section)
 {
+    dvbpsi_cat_decoder_t* p_cat_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
@@ -269,8 +270,7 @@ void dvbpsi_cat_sections_gather(dvbpsi_t *p_dvbpsi,
     }
 
     /* */
-    dvbpsi_cat_decoder_t* p_cat_decoder
-                          = (dvbpsi_cat_decoder_t*)p_dvbpsi->p_decoder;
+    p_cat_decoder = (dvbpsi_cat_decoder_t*)p_dvbpsi->p_decoder;
 
     /* TS discontinuity check */
     if (p_cat_decoder->b_discontinuity)
diff --git a/src/tables/eit.c b/src/tables/eit.c
index 6e359a2..c8314f7 100644
--- a/src/tables/eit.c
+++ b/src/tables/eit.c
@@ -57,10 +57,13 @@
 bool dvbpsi_eit_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                            dvbpsi_eit_callback pf_callback, void* p_cb_data)
 {
+    dvbpsi_demux_t* p_demux;
+    dvbpsi_eit_decoder_t*  p_eit_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
 
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension) != NULL)
     {
@@ -71,14 +74,12 @@ bool dvbpsi_eit_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
         return false;
     }
 
-    dvbpsi_eit_decoder_t*  p_eit_decoder;
     p_eit_decoder = (dvbpsi_eit_decoder_t*) dvbpsi_decoder_new(NULL,
                                              0, true, sizeof(dvbpsi_eit_decoder_t));
     if (p_eit_decoder == NULL)
         return false;
 
     /* subtable decoder configuration */
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_eit_detach,
                                          dvbpsi_eit_sections_gather, DVBPSI_DECODER(p_eit_decoder));
     if (p_subdec == NULL)
@@ -106,12 +107,14 @@ bool dvbpsi_eit_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
 void dvbpsi_eit_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
           uint16_t i_extension)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_eit_decoder_t* p_eit_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
 
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if (p_subdec == NULL)
     {
@@ -122,7 +125,6 @@ void dvbpsi_eit_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id,
         return;
     }
 
-    dvbpsi_eit_decoder_t* p_eit_decoder;
     p_eit_decoder = (dvbpsi_eit_decoder_t*)p_subdec->p_decoder;
     if (p_eit_decoder->p_building_eit)
         dvbpsi_eit_delete(p_eit_decoder->p_building_eit);
@@ -328,10 +330,10 @@ static bool dvbpsi_CheckEIT(dvbpsi_t *p_dvbpsi, dvbpsi_eit_decoder_t *p_eit_deco
 
 static bool dvbpsi_IsCompleteEIT(dvbpsi_eit_decoder_t* p_eit_decoder, dvbpsi_psi_section_t* p_section)
 {
-    assert(p_eit_decoder);
-
     bool b_complete = false;
 
+    assert(p_eit_decoder);
+
     /* As there may be gaps in the section_number fields (see below), we
      * have to wait until we have received a section_number twice or
      * until we have a received a section_number which is
@@ -424,13 +426,15 @@ static bool dvbpsi_AddSectionEIT(dvbpsi_t *p_dvbpsi, dvbpsi_eit_decoder_t *p_eit
 void dvbpsi_eit_sections_gather(dvbpsi_t *p_dvbpsi, dvbpsi_decoder_t *p_private_decoder,
                                dvbpsi_psi_section_t *p_section)
 {
-    assert(p_dvbpsi);
-    assert(p_dvbpsi->p_decoder);
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_eit_decoder_t* p_eit_decoder;
 
-    const uint8_t i_table_id = (p_section->i_table_id >= 0x4e &&
+	const uint8_t i_table_id = (p_section->i_table_id >= 0x4e &&
                                 p_section->i_table_id <= 0x6f) ?
                                     p_section->i_table_id : 0x4e;
 
+    assert(p_dvbpsi);
+    assert(p_dvbpsi->p_decoder);
     if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, i_table_id, "EIT decoder"))
     {
         dvbpsi_DeletePSISections(p_section);
@@ -438,9 +442,8 @@ void dvbpsi_eit_sections_gather(dvbpsi_t *p_dvbpsi, dvbpsi_decoder_t *p_private_
     }
 
     /* We have a valid EIT section */
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
-    dvbpsi_eit_decoder_t* p_eit_decoder
-                        = (dvbpsi_eit_decoder_t*)p_private_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_eit_decoder = (dvbpsi_eit_decoder_t*)p_private_decoder;
 
     /* TS discontinuity check */
     if (p_demux->b_discontinuity)
@@ -541,12 +544,13 @@ void dvbpsi_eit_sections_decode(dvbpsi_eit_t* p_eit,
             dvbpsi_eit_event_t *p_event = dvbpsi_eit_event_add(p_eit,
                                                 i_event_id, i_start_time, i_duration,
                                                 i_running_status, b_free_ca, i_ev_length);
+			uint8_t* p_ev_end;
             if (!p_event)
                 break;
 
             /* Event Descriptors */
             p_byte += 12;
-            uint8_t *p_ev_end = p_byte + i_ev_length;
+            p_ev_end = p_byte + i_ev_length;
             if (p_ev_end > p_section->p_payload_end)
                 p_ev_end = p_section->p_payload_end;
             while (p_byte < p_ev_end)
diff --git a/src/tables/nit.c b/src/tables/nit.c
index c4bca0b..8c57ada 100644
--- a/src/tables/nit.c
+++ b/src/tables/nit.c
@@ -59,10 +59,13 @@ bool dvbpsi_nit_attach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
                       uint16_t i_extension, dvbpsi_nit_callback pf_callback,
                       void* p_cb_data)
 {
+	dvbpsi_demux_t* p_demux;
+    dvbpsi_nit_decoder_t*  p_nit_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
 
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
     {
@@ -73,14 +76,12 @@ bool dvbpsi_nit_attach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
         return false;
     }
 
-    dvbpsi_nit_decoder_t*  p_nit_decoder;
     p_nit_decoder = (dvbpsi_nit_decoder_t*) dvbpsi_decoder_new(NULL,
                                              0, true, sizeof(dvbpsi_nit_decoder_t));
     if (p_nit_decoder == NULL)
         return false;
 
     /* subtable decoder configuration */
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_nit_detach,
                                          dvbpsi_nit_sections_gather, DVBPSI_DECODER(p_nit_decoder));
     if (p_subdec == NULL)
@@ -111,6 +112,7 @@ void dvbpsi_nit_detach(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_exten
     dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
 
     dvbpsi_demux_subdec_t* p_subdec;
+    dvbpsi_nit_decoder_t* p_nit_decoder;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if (p_subdec == NULL)
     {
@@ -121,7 +123,6 @@ void dvbpsi_nit_detach(dvbpsi_t * p_dvbpsi, uint8_t i_table_id, uint16_t i_exten
         return;
     }
 
-    dvbpsi_nit_decoder_t* p_nit_decoder;
     p_nit_decoder = (dvbpsi_nit_decoder_t*)p_subdec->p_decoder;
     if (p_nit_decoder->p_building_nit)
         dvbpsi_nit_delete(p_nit_decoder->p_building_nit);
@@ -299,11 +300,11 @@ static void dvbpsi_ReInitNIT(dvbpsi_nit_decoder_t* p_decoder, const bool b_force
 static bool dvbpsi_CheckNIT(dvbpsi_t *p_dvbpsi, dvbpsi_nit_decoder_t *p_nit_decoder,
                             dvbpsi_psi_section_t *p_section)
 {
+    bool b_reinit = false;
+
     assert(p_dvbpsi);
     assert(p_nit_decoder);
 
-    bool b_reinit = false;
-
     if (p_nit_decoder->p_building_nit->i_version != p_section->i_version)
     {
         /* version_number */
@@ -360,12 +361,13 @@ void dvbpsi_nit_sections_gather(dvbpsi_t *p_dvbpsi,
                                 dvbpsi_decoder_t *p_private_decoder,
                                 dvbpsi_psi_section_t *p_section)
 {
-    assert(p_dvbpsi);
+    dvbpsi_nit_decoder_t* p_nit_decoder;
 
-    const uint8_t i_table_id = ((p_section->i_table_id == 0x40) ||
+	const uint8_t i_table_id = ((p_section->i_table_id == 0x40) ||
                                 (p_section->i_table_id == 0x41)) ?
                                     p_section->i_table_id : 0x40;
 
+    assert(p_dvbpsi);
     if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, i_table_id, "NIT decoder"))
     {
         dvbpsi_DeletePSISections(p_section);
@@ -373,8 +375,7 @@ void dvbpsi_nit_sections_gather(dvbpsi_t *p_dvbpsi,
     }
 
     /* */
-    dvbpsi_nit_decoder_t* p_nit_decoder
-                        = (dvbpsi_nit_decoder_t*)p_private_decoder;
+	p_nit_decoder = (dvbpsi_nit_decoder_t*)p_private_decoder;
 
     /* We have a valid NIT section */
     if (p_nit_decoder->i_network_id != p_section->i_extension)
diff --git a/src/tables/pat.c b/src/tables/pat.c
index 0ad625c..4dcf3ad 100644
--- a/src/tables/pat.c
+++ b/src/tables/pat.c
@@ -53,11 +53,11 @@
 bool dvbpsi_pat_attach(dvbpsi_t *p_dvbpsi, dvbpsi_pat_callback pf_callback,
                       void* p_cb_data)
 {
+    dvbpsi_pat_decoder_t *p_pat_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder == NULL);
 
     /* PSI decoder configuration and initial state */
-    dvbpsi_pat_decoder_t *p_pat_decoder;
     p_pat_decoder = (dvbpsi_pat_decoder_t*) dvbpsi_decoder_new(&dvbpsi_pat_sections_gather,
                                                 1024, true, sizeof(dvbpsi_pat_decoder_t));
     if (p_pat_decoder == NULL)
@@ -79,10 +79,11 @@ bool dvbpsi_pat_attach(dvbpsi_t *p_dvbpsi, dvbpsi_pat_callback pf_callback,
  *****************************************************************************/
 void dvbpsi_pat_detach(dvbpsi_t *p_dvbpsi)
 {
+    dvbpsi_pat_decoder_t* p_pat_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_pat_decoder_t* p_pat_decoder = (dvbpsi_pat_decoder_t*)p_dvbpsi->p_decoder;
+    p_pat_decoder = (dvbpsi_pat_decoder_t*)p_dvbpsi->p_decoder;
     if (p_pat_decoder->p_building_pat)
         dvbpsi_pat_delete(p_pat_decoder->p_building_pat);
     p_pat_decoder->p_building_pat = NULL;
@@ -207,9 +208,10 @@ static void dvbpsi_ReInitPAT(dvbpsi_pat_decoder_t* p_decoder, const bool b_force
 static bool dvbpsi_CheckPAT(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section)
 {
     bool b_reinit = false;
+    dvbpsi_pat_decoder_t* p_pat_decoder;
+
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_pat_decoder_t* p_pat_decoder;
     p_pat_decoder = (dvbpsi_pat_decoder_t *)p_dvbpsi->p_decoder;
 
     /* Perform a few sanity checks */
@@ -361,7 +363,8 @@ bool dvbpsi_pat_sections_decode(dvbpsi_pat_t* p_pat, dvbpsi_psi_section_t* p_sec
     bool b_valid = false;
     while (p_section)
     {
-        for (uint8_t *p_byte = p_section->p_payload_start;
+		uint8_t* p_byte;
+        for (p_byte = p_section->p_payload_start;
             p_byte < p_section->p_payload_end;
             p_byte += 4)
         {
diff --git a/src/tables/pmt.c b/src/tables/pmt.c
index 9a89f93..5ed80ba 100644
--- a/src/tables/pmt.c
+++ b/src/tables/pmt.c
@@ -55,10 +55,11 @@
 bool dvbpsi_pmt_attach(dvbpsi_t *p_dvbpsi, uint16_t i_program_number,
                       dvbpsi_pmt_callback pf_callback, void* p_cb_data)
 {
+    dvbpsi_pmt_decoder_t* p_pmt_decoder;
+
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder == NULL);
 
-    dvbpsi_pmt_decoder_t* p_pmt_decoder;
     p_pmt_decoder = (dvbpsi_pmt_decoder_t*) dvbpsi_decoder_new(&dvbpsi_pmt_sections_gather,
                                             1024, true, sizeof(dvbpsi_pmt_decoder_t));
     if (p_pmt_decoder == NULL)
@@ -82,10 +83,10 @@ bool dvbpsi_pmt_attach(dvbpsi_t *p_dvbpsi, uint16_t i_program_number,
  *****************************************************************************/
 void dvbpsi_pmt_detach(dvbpsi_t *p_dvbpsi)
 {
+    dvbpsi_pmt_decoder_t* p_pmt_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_pmt_decoder_t* p_pmt_decoder;
     p_pmt_decoder = (dvbpsi_pmt_decoder_t*)p_dvbpsi->p_decoder;
     if (p_pmt_decoder->p_building_pmt)
         dvbpsi_pmt_delete(p_pmt_decoder->p_building_pmt);
@@ -261,9 +262,10 @@ static void dvbpsi_ReInitPMT(dvbpsi_pmt_decoder_t* p_decoder, const bool b_force
 static bool dvbpsi_CheckPMT(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section)
 {
     bool b_reinit = false;
+    dvbpsi_pmt_decoder_t* p_pmt_decoder;
+
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_pmt_decoder_t* p_pmt_decoder;
     p_pmt_decoder = (dvbpsi_pmt_decoder_t *)p_dvbpsi->p_decoder;
 
     if (p_pmt_decoder->p_building_pmt->i_version != p_section->i_version)
@@ -321,6 +323,7 @@ static bool dvbpsi_AddSectionPMT(dvbpsi_t *p_dvbpsi, dvbpsi_pmt_decoder_t *p_pmt
  *****************************************************************************/
 void dvbpsi_pmt_sections_gather(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t* p_section)
 {
+    dvbpsi_pmt_decoder_t* p_pmt_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
@@ -331,7 +334,7 @@ void dvbpsi_pmt_sections_gather(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t* p_sect
     }
 
     /* */
-    dvbpsi_pmt_decoder_t* p_pmt_decoder = (dvbpsi_pmt_decoder_t*)p_dvbpsi->p_decoder;
+    p_pmt_decoder = (dvbpsi_pmt_decoder_t*)p_dvbpsi->p_decoder;
     assert(p_pmt_decoder);
 
     /* We have a valid PMT section */
diff --git a/src/tables/rst.c b/src/tables/rst.c
index 2198c61..8816809 100644
--- a/src/tables/rst.c
+++ b/src/tables/rst.c
@@ -56,10 +56,10 @@
 bool dvbpsi_rst_attach(dvbpsi_t *p_dvbpsi, dvbpsi_rst_callback pf_callback,
                       void* p_cb_data)
 {
+    dvbpsi_rst_decoder_t* p_rst_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder == NULL);
 
-    dvbpsi_rst_decoder_t* p_rst_decoder;
     p_rst_decoder = (dvbpsi_rst_decoder_t*) dvbpsi_decoder_new(&dvbpsi_rst_sections_gather,
                                                 1024, true, sizeof(dvbpsi_rst_decoder_t));
     if (p_rst_decoder == NULL)
@@ -81,11 +81,11 @@ bool dvbpsi_rst_attach(dvbpsi_t *p_dvbpsi, dvbpsi_rst_callback pf_callback,
  *****************************************************************************/
 void dvbpsi_rst_detach(dvbpsi_t *p_dvbpsi)
 {
+    dvbpsi_rst_decoder_t* p_rst_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_rst_decoder_t* p_rst_decoder
-                        = (dvbpsi_rst_decoder_t*)p_dvbpsi->p_decoder;
+    p_rst_decoder = (dvbpsi_rst_decoder_t*)p_dvbpsi->p_decoder;
     if (p_rst_decoder->p_building_rst)
         dvbpsi_rst_delete(p_rst_decoder->p_building_rst);
     p_rst_decoder->p_building_rst = NULL;
@@ -346,6 +346,7 @@ error:
 void dvbpsi_rst_sections_gather(dvbpsi_t *p_dvbpsi,
                               dvbpsi_psi_section_t* p_section)
 {
+    dvbpsi_rst_decoder_t* p_rst_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
@@ -356,8 +357,7 @@ void dvbpsi_rst_sections_gather(dvbpsi_t *p_dvbpsi,
     }
 
     /* */
-    dvbpsi_rst_decoder_t* p_rst_decoder
-                          = (dvbpsi_rst_decoder_t*)p_dvbpsi->p_decoder;
+    p_rst_decoder = (dvbpsi_rst_decoder_t*)p_dvbpsi->p_decoder;
 
     /* TS discontinuity check */
     if (p_rst_decoder->b_discontinuity)
diff --git a/src/tables/sdt.c b/src/tables/sdt.c
index a159773..bd3b19f 100644
--- a/src/tables/sdt.c
+++ b/src/tables/sdt.c
@@ -56,10 +56,13 @@
 bool dvbpsi_sdt_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                       dvbpsi_sdt_callback pf_callback, void* p_cb_data)
 {
+    dvbpsi_demux_t* p_demux;
+    dvbpsi_sdt_decoder_t*  p_sdt_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
 
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
     {
@@ -70,14 +73,12 @@ bool dvbpsi_sdt_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
         return false;
     }
 
-    dvbpsi_sdt_decoder_t*  p_sdt_decoder;
     p_sdt_decoder = (dvbpsi_sdt_decoder_t*) dvbpsi_decoder_new(NULL,
                                              0, true, sizeof(dvbpsi_sdt_decoder_t));
     if (p_sdt_decoder == NULL)
         return false;
 
     /* subtable decoder configuration */
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_sdt_detach,
                                          dvbpsi_sdt_sections_gather, DVBPSI_DECODER(p_sdt_decoder));
     if (p_subdec == NULL)
@@ -104,12 +105,14 @@ bool dvbpsi_sdt_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
  *****************************************************************************/
 void dvbpsi_sdt_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
 {
+    dvbpsi_demux_subdec_t* p_subdec;
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_sdt_decoder_t* p_sdt_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
 
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if (p_subdec == NULL)
     {
@@ -122,7 +125,6 @@ void dvbpsi_sdt_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
 
     assert(p_subdec->p_decoder);
 
-    dvbpsi_sdt_decoder_t* p_sdt_decoder;
     p_sdt_decoder = (dvbpsi_sdt_decoder_t*)p_subdec->p_decoder;
     if (p_sdt_decoder->p_building_sdt)
         dvbpsi_sdt_delete(p_sdt_decoder->p_building_sdt);
@@ -350,13 +352,15 @@ void dvbpsi_sdt_sections_gather(dvbpsi_t *p_dvbpsi,
                                 dvbpsi_decoder_t *p_private_decoder,
                                 dvbpsi_psi_section_t * p_section)
 {
-    assert(p_dvbpsi);
-    assert(p_dvbpsi->p_decoder);
-
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_sdt_decoder_t *p_sdt_decoder;
     const uint8_t i_table_id = (p_section->i_table_id == 0x42 ||
                                 p_section->i_table_id == 0x46) ?
                                     p_section->i_table_id : 0x42;
 
+    assert(p_dvbpsi);
+    assert(p_dvbpsi->p_decoder);
+
     if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, i_table_id, "SDT decoder"))
     {
         dvbpsi_DeletePSISections(p_section);
@@ -364,9 +368,8 @@ void dvbpsi_sdt_sections_gather(dvbpsi_t *p_dvbpsi,
     }
 
     /* We have a valid SDT section */
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_decoder;
-    dvbpsi_sdt_decoder_t *p_sdt_decoder
-                        = (dvbpsi_sdt_decoder_t*)p_private_decoder;
+    p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_decoder;
+    p_sdt_decoder = (dvbpsi_sdt_decoder_t*)p_private_decoder;
 
     /* TS discontinuity check */
     if (p_demux->b_discontinuity)
diff --git a/src/tables/sis.c b/src/tables/sis.c
index bbd82b8..a82dc63 100644
--- a/src/tables/sis.c
+++ b/src/tables/sis.c
@@ -56,10 +56,13 @@
 bool dvbpsi_sis_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                       dvbpsi_sis_callback pf_callback, void* p_cb_data)
 {
+    dvbpsi_demux_t* p_demux;
+    dvbpsi_sis_decoder_t*  p_sis_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
 
     i_extension = 0;
 
@@ -72,14 +75,12 @@ bool dvbpsi_sis_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
         return false;
     }
 
-    dvbpsi_sis_decoder_t*  p_sis_decoder;
     p_sis_decoder = (dvbpsi_sis_decoder_t*) dvbpsi_decoder_new(NULL,
                                              0, true, sizeof(dvbpsi_sis_decoder_t));
     if (p_sis_decoder == NULL)
         return false;
 
     /* subtable decoder configuration */
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_sis_detach,
                                          dvbpsi_sis_sections_gather, DVBPSI_DECODER(p_sis_decoder));
     if (p_subdec == NULL)
@@ -106,13 +107,15 @@ bool dvbpsi_sis_attach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
  *****************************************************************************/
 void dvbpsi_sis_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extension)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_sis_decoder_t* p_sis_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
 
     i_extension = 0;
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
     if (p_subdec == NULL)
     {
@@ -125,7 +128,6 @@ void dvbpsi_sis_detach(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
 
     assert(p_subdec->p_decoder);
 
-    dvbpsi_sis_decoder_t* p_sis_decoder;
     p_sis_decoder = (dvbpsi_sis_decoder_t*)p_subdec->p_decoder;
     if (p_sis_decoder->p_building_sis)
         dvbpsi_sis_delete(p_sis_decoder->p_building_sis);
@@ -332,6 +334,8 @@ void dvbpsi_sis_sections_gather(dvbpsi_t *p_dvbpsi,
                               dvbpsi_decoder_t *p_decoder,
                               dvbpsi_psi_section_t * p_section)
 {
+    dvbpsi_demux_t *p_demux;
+    dvbpsi_sis_decoder_t * p_sis_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
@@ -342,8 +346,8 @@ void dvbpsi_sis_sections_gather(dvbpsi_t *p_dvbpsi,
     }
 
     /* */
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
-    dvbpsi_sis_decoder_t * p_sis_decoder = (dvbpsi_sis_decoder_t*)p_decoder;
+    p_demux = (dvbpsi_demux_t *) p_dvbpsi->p_decoder;
+    p_sis_decoder = (dvbpsi_sis_decoder_t*)p_decoder;
 
     if (p_section->b_private_indicator)
     {
@@ -429,6 +433,8 @@ void dvbpsi_sis_sections_decode(dvbpsi_t* p_dvbpsi, dvbpsi_sis_t* p_sis,
         for (p_byte = p_section->p_payload_start + 3;
              p_byte < p_section->p_payload_end; )
         {
+            uint32_t i_splice_command_length;
+			uint8_t* p_desc;
             p_sis->i_protocol_version = p_byte[3];
             p_sis->b_encrypted_packet = ((p_byte[4] & 0x80)>>8);
             /* NOTE: cannot handle encrypted packet */
@@ -443,7 +449,7 @@ void dvbpsi_sis_sections_decode(dvbpsi_t* p_dvbpsi, dvbpsi_sis_t* p_sis,
             p_sis->i_splice_command_length = ((p_byte[11] & 0x0F) << 8) | p_byte[12];
             p_sis->i_splice_command_type = p_byte[13];
 
-            uint32_t i_splice_command_length = p_sis->i_splice_command_length;
+            i_splice_command_length = p_sis->i_splice_command_length;
             if (p_sis->i_splice_command_length == 0xfff)
             {
                 /* FIXME: size 0xfff of splice_command_section is undefined */
@@ -465,7 +471,7 @@ void dvbpsi_sis_sections_decode(dvbpsi_t* p_dvbpsi, dvbpsi_sis_t* p_sis,
             }
 
             /* Service descriptors */
-            uint8_t *p_desc = p_byte + 13 + i_splice_command_length;
+            p_desc = p_byte + 13 + i_splice_command_length;
             p_sis->i_descriptors_length = (p_desc[0] << 8) | p_desc[1];
 
             p_desc += 1;
@@ -509,6 +515,9 @@ void dvbpsi_sis_sections_decode(dvbpsi_t* p_dvbpsi, dvbpsi_sis_t* p_sis,
 dvbpsi_psi_section_t *dvbpsi_sis_sections_generate(dvbpsi_t *p_dvbpsi, dvbpsi_sis_t* p_sis)
 {
     dvbpsi_psi_section_t * p_current = dvbpsi_NewPSISection(1024);
+	uint32_t i_desc_start;
+    uint32_t i_desc_length = 0;
+    dvbpsi_descriptor_t * p_descriptor;
 
     p_current->i_table_id = 0xFC;
     p_current->b_syntax_indicator = false;
@@ -537,7 +546,7 @@ dvbpsi_psi_section_t *dvbpsi_sis_sections_generate(dvbpsi_t *p_dvbpsi, dvbpsi_si
     p_current->p_data[12] = (uint8_t) (p_sis->i_splice_command_length & 0xFF);
     p_current->p_data[13] = p_sis->i_splice_command_type;
 
-    uint32_t i_desc_start = 13 + p_sis->i_splice_command_length;
+    i_desc_start = 13 + p_sis->i_splice_command_length;
     if (p_sis->i_splice_command_length == 0xfff)
     {
         /* FIXME: size 0xfff of splice_command_section is undefined */
@@ -552,9 +561,7 @@ dvbpsi_psi_section_t *dvbpsi_sis_sections_generate(dvbpsi_t *p_dvbpsi, dvbpsi_si
 
     p_current->p_payload_end += (i_desc_start + 1);
 
-    uint32_t i_desc_length = 0;
-
-    dvbpsi_descriptor_t * p_descriptor = p_sis->p_first_descriptor;
+    p_descriptor = p_sis->p_first_descriptor;
     while ((p_descriptor != NULL) && (p_current->i_length <= 1018))
     {
         i_desc_length += p_descriptor->i_length + 2;
diff --git a/src/tables/tot.c b/src/tables/tot.c
index 18b2ba7..f0aca2b 100644
--- a/src/tables/tot.c
+++ b/src/tables/tot.c
@@ -58,10 +58,13 @@
 bool dvbpsi_tot_attach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_extension,
                        dvbpsi_tot_callback pf_callback, void* p_cb_data)
 {
+	dvbpsi_demux_t* p_demux;
+    dvbpsi_tot_decoder_t *p_tot_decoder;
+    dvbpsi_demux_subdec_t* p_subdec;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t* p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
+    p_demux = (dvbpsi_demux_t*)p_dvbpsi->p_decoder;
 
     i_extension = 0; /* NOTE: force to 0 when handling TDT/TOT */
     if (dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension))
@@ -73,14 +76,12 @@ bool dvbpsi_tot_attach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
         return false;
     }
 
-    dvbpsi_tot_decoder_t *p_tot_decoder;
     p_tot_decoder = (dvbpsi_tot_decoder_t *) dvbpsi_decoder_new(NULL,
                                                 0, true, sizeof(dvbpsi_tot_decoder_t));
     if (p_tot_decoder == NULL)
         return false;
 
     /* subtable decoder configuration */
-    dvbpsi_demux_subdec_t* p_subdec;
     p_subdec = dvbpsi_NewDemuxSubDecoder(i_table_id, i_extension, dvbpsi_tot_detach,
                                          dvbpsi_tot_sections_gather, DVBPSI_DECODER(p_tot_decoder));
     if (p_subdec == NULL)
@@ -108,11 +109,13 @@ bool dvbpsi_tot_attach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id, uint16_t i_extens
 void dvbpsi_tot_detach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
                       uint16_t i_extension)
 {
+	dvbpsi_demux_t* p_demux;
+    dvbpsi_demux_subdec_t* p_subdec;
+    dvbpsi_tot_decoder_t* p_tot_decoder;
     assert(p_dvbpsi);
     assert(p_dvbpsi->p_decoder);
 
-    dvbpsi_demux_t *p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_decoder;
-    dvbpsi_demux_subdec_t* p_subdec;
+    p_demux = (dvbpsi_demux_t *)p_dvbpsi->p_decoder;
 
     i_extension = 0; /* NOTE: force to 0 when handling TDT/TOT */
     p_subdec = dvbpsi_demuxGetSubDec(p_demux, i_table_id, i_extension);
@@ -127,7 +130,6 @@ void dvbpsi_tot_detach(dvbpsi_t* p_dvbpsi, uint8_t i_table_id,
 
     assert(p_subdec->p_decoder);
 
-    dvbpsi_tot_decoder_t* p_tot_decoder;
     p_tot_decoder = (dvbpsi_tot_decoder_t*)p_subdec->p_decoder;
     if (p_tot_decoder->p_building_tot)
         dvbpsi_tot_delete(p_tot_decoder->p_building_tot);
@@ -310,12 +312,13 @@ void dvbpsi_tot_sections_gather(dvbpsi_t* p_dvbpsi,
                                 dvbpsi_decoder_t* p_decoder,
                                 dvbpsi_psi_section_t* p_section)
 {
-    assert(p_dvbpsi);
-    assert(p_dvbpsi->p_decoder);
-
     const uint8_t i_table_id = ((p_section->i_table_id == 0x70 ||  /* TDT */
                                  p_section->i_table_id == 0x73)) ? /* TOT */
                                     p_section->i_table_id : 0x70;
+    dvbpsi_tot_decoder_t* p_tot_decoder;
+
+    assert(p_dvbpsi);
+    assert(p_dvbpsi->p_decoder);
 
     if (!dvbpsi_CheckPSISection(p_dvbpsi, p_section, i_table_id, "TDT/TOT decoder"))
     {
@@ -324,7 +327,7 @@ void dvbpsi_tot_sections_gather(dvbpsi_t* p_dvbpsi,
     }
 
     /* Valid TDT/TOT section */
-    dvbpsi_tot_decoder_t* p_tot_decoder = (dvbpsi_tot_decoder_t*)p_decoder;
+    p_tot_decoder = (dvbpsi_tot_decoder_t*)p_decoder;
 
     /* TS discontinuity check */
     if (p_tot_decoder->b_discontinuity)
-- 
1.8.3.4


From 2ee9a5bf1388bf855bf15422a8dd3d732f4ed5c4 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Fri, 12 Sep 2014 12:00:43 +0200
Subject: Fix headers for gcc2

* They use "bool", so stdbool.h must be included.

diff --git a/src/descriptor.h b/src/descriptor.h
index f344a73..e8c4f7f 100644
--- a/src/descriptor.h
+++ b/src/descriptor.h
@@ -35,6 +35,8 @@
 #ifndef _DVBPSI_DESCRIPTOR_H_
 #define _DVBPSI_DESCRIPTOR_H_
 
+#include <stdbool.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/descriptors/dr.h b/src/descriptors/dr.h
index 778b2f0..dbe4798 100644
--- a/src/descriptors/dr.h
+++ b/src/descriptors/dr.h
@@ -31,6 +31,8 @@
 #ifndef _DVBPSI_DR_H_
 #define _DVBPSI_DR_H_
 
+#include <stdbool.h>
+
 #include "dr_02.h"
 #include "dr_03.h"
 #include "dr_04.h"
diff --git a/src/dvbpsi.h b/src/dvbpsi.h
index 1a5f859..d8489f1 100644
--- a/src/dvbpsi.h
+++ b/src/dvbpsi.h
@@ -35,6 +35,8 @@
 #ifndef _DVBPSI_DVBPSI_H_
 #define _DVBPSI_DVBPSI_H_
 
+#include <stdbool.h>
+
 #define DVBPSI_VERSION      1.2.0              /*!< Human readible DVBPSI version*/
 #define DVBPSI_VERSION_INT  ((1<<16)+(2<<8)+0) /*!< Machine readible DVBPSI version */
 
diff --git a/src/tables/pat.h b/src/tables/pat.h
index fe1a6ed..284a0fa 100644
--- a/src/tables/pat.h
+++ b/src/tables/pat.h
@@ -33,6 +33,8 @@
 #ifndef _DVBPSI_PAT_H_
 #define _DVBPSI_PAT_H_
 
+#include <stdbool.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/tables/pmt.h b/src/tables/pmt.h
index f0f4fa3..c1e3117 100644
--- a/src/tables/pmt.h
+++ b/src/tables/pmt.h
@@ -34,6 +34,8 @@
 #ifndef _DVBPSI_PMT_H_
 #define _DVBPSI_PMT_H_
 
+#include <stdbool.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
-- 
1.8.3.4

