[Swfed-svn] swfed-svn [408] NULL ガード ( 画像入れ替えが絡む部分を中心に )

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 10日 (木) 22:15:53 JST


Revision: 408
          http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=408
Author:   yoya
Date:     2011-03-10 22:15:53 +0900 (Thu, 10 Mar 2011)

Log Message:
-----------
NULL ガード (画像入れ替えが絡む部分を中心に)
- 引数の NULL チェックを増やした
- 自動変数のポインタの NULL 代入を増やした

Modified Paths:
--------------
    trunk/src/swf_jpeg.c
    trunk/src/swf_png.c
    trunk/src/swf_tag.c
    trunk/src/swf_tag_jpeg.c
    trunk/src/swf_tag_lossless.c


-------------- next part --------------
Modified: trunk/src/swf_jpeg.c
===================================================================
--- trunk/src/swf_jpeg.c	2011-03-10 13:01:44 UTC (rev 407)
+++ trunk/src/swf_jpeg.c	2011-03-10 13:15:53 UTC (rev 408)
@@ -14,11 +14,15 @@
 jpegconv_std2swf(unsigned char *data, unsigned long data_len,
                  unsigned long *length) {
     jpeg_segment_t *jpeg_data = NULL;
-    jpeg_segment_t *jpeg_output;
-    unsigned char *d;
+    jpeg_segment_t *jpeg_output = NULL;
+    unsigned char *d = NULL;
     unsigned long d_len;
     int m;
     unsigned char *ret_data;
+    if (data == NULL) {
+        fprintf(stderr, "jpegconv_std2swf: data == NULL\n");
+        return NULL;
+    }
     jpeg_data = jpeg_segment_parse(data, data_len, 1);
     if (jpeg_data == NULL) {
         fprintf(stderr, "jpegconv_std2swf: Can't create jpeg segment for data\n");
@@ -56,13 +60,17 @@
 jpegconv_swf2std(unsigned char *data, unsigned long data_len,
                  unsigned long *length, unsigned char *table_data,
                  unsigned long table_data_len) {
-    jpeg_segment_t *jpeg_data, *jpeg_table = NULL;
-    jpeg_segment_t *jpeg_output;
+    jpeg_segment_t *jpeg_data = NULL, *jpeg_table = NULL;
+    jpeg_segment_t *jpeg_output = NULL;
     int m;
-    unsigned char *d;
+    unsigned char *d = NULL;
     unsigned long d_len;
-    unsigned char *ret_data;
+    unsigned char *ret_data = NULL;
     *length = 0;
+    if (data == NULL) {
+        fprintf(stderr, "jpegconv_swf2std: data == NULL\n");
+        return NULL;
+    }
     jpeg_data = jpeg_segment_parse(data, data_len, 1);
     if (jpeg_data == NULL) {
             fprintf(stderr, "jpegconv_swf2std: Can't create jpeg segment for data\n");

Modified: trunk/src/swf_png.c
===================================================================
--- trunk/src/swf_png.c	2011-03-10 13:01:44 UTC (rev 407)
+++ trunk/src/swf_png.c	2011-03-10 13:15:53 UTC (rev 408)
@@ -92,13 +92,17 @@
     png_uint_32 png_width = 0, png_height = 0;
     volatile png_bytepp png_image_data = NULL;
     png_uint_32 x, y;
-    void *image_data;
+    void *image_data = NULL;
     png_color *palette = NULL;
     int palette_num = 0;
     png_bytep trans = NULL;
     int num_trans = 0;
     png_color_16p trans_values = NULL;
 
+    if (png_data == NULL) {
+        fprintf(stderr, "pngconv_png2lossless: png_data == NULL\n");
+        return NULL;
+    }
     is_png = png_check_sig((png_bytep)png_data, 8);
     if (! is_png) {
         fprintf(stderr, "pngconv_png2lossless: is not PNG!\n");
@@ -281,6 +285,10 @@
     volatile png_bytepp png_image_data = NULL;
     png_uint_32 x, y;
     volatile png_colorp png_palette = NULL;
+    if (image_data == NULL) {
+        fprintf(stderr, "pngconv_lossless2png: image_data == NULL\n");
+        return NULL;
+    }
     if ((format != 3) && (format != 5)) {
         fprintf(stderr, "jpegconv_lossless2png: format=%d not implemented yes.\n", format);
         return NULL;

Modified: trunk/src/swf_tag.c
===================================================================
--- trunk/src/swf_tag.c	2011-03-10 13:01:44 UTC (rev 407)
+++ trunk/src/swf_tag.c	2011-03-10 13:15:53 UTC (rev 408)
@@ -78,12 +78,13 @@
 }
 
 swf_tag_t *swf_tag_create(bitstream_t *bs) {
-    swf_tag_t *tag = calloc(sizeof(*tag), 1);
+    swf_tag_t *tag = NULL;
     unsigned short tag_and_length;
     if (bs == NULL) {
         fprintf(stderr, "swf_tag_create: bs == NULL\n");
         return NULL;
     }
+    tag = calloc(sizeof(*tag), 1);
     tag_and_length = bitstream_getbytesLE(bs, 2);
     if (tag_and_length == (unsigned short) -1) {
         fprintf(stderr, "swf_tag_create: tag_and_length(short) == -1\n");
@@ -141,6 +142,10 @@
         fprintf(stderr, "swf_tag_and_length_build: bs == NULL\n");
         return 1;
     }
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_and_length_build: tag == NULL\n");
+        return 1;
+    }
     if (tag->length >= 0x3f) {
         tag->length_longformat = 1;
     } else {
@@ -170,14 +175,18 @@
 }
 
 int swf_tag_build(bitstream_t *bs, swf_tag_t *tag, struct swf_object_ *swf) {
-    swf_tag_info_t *tag_info;
-    unsigned char *data;
+    swf_tag_info_t *tag_info = NULL;
+    unsigned char *data = NULL;
     unsigned long data_len = 0;
-    swf_tag_detail_handler_t * detail_handler;
+    swf_tag_detail_handler_t * detail_handler = NULL;
     if (bs == NULL) {
         fprintf(stderr, "swf_tag_and_length_build: bs == NULL\n");
         return 1;
     }
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_and_length_build: tag == NULL\n");
+        return 1;
+    }
 //    fprintf(stderr, "XXX: swf_tag_build: tag->tag=%d\n",tag->tag);
     if (tag->data) {
         swf_tag_and_length_build(bs, tag);
@@ -213,8 +222,8 @@
 
 void
 swf_tag_print(swf_tag_t *tag, struct swf_object_ *swf, int indent_depth) {
-    swf_tag_info_t *tag_info;
-    const char *tag_name;
+    swf_tag_info_t *tag_info = NULL;
+    const char *tag_name = NULL;
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_print: tag == NULL\n");
         return ;
@@ -239,7 +248,7 @@
 }
 
 int swf_tag_create_input_detail(swf_tag_t *tag, struct swf_object_ *swf) {
-    swf_tag_info_t *tag_info;
+    swf_tag_info_t *tag_info = NULL;
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_create_input_detail: tag == NULL\n");
         return 1;
@@ -269,8 +278,13 @@
 
 int
 swf_tag_get_cid(swf_tag_t *tag) {
-    swf_tag_info_t *tag_info;
-    int tag_no = tag->tag;
+    swf_tag_info_t *tag_info = NULL;
+    int tag_no;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_get_cid: tag == NULL\n");
+        return 1;
+    }
+    tag_no = tag->tag;
     tag_info = get_swf_tag_info(tag_no);
     if (tag_info && tag_info->detail_handler) {
         swf_tag_detail_handler_t * detail_handler = tag_info->detail_handler();
@@ -306,7 +320,12 @@
 int
 swf_tag_replace_cid(swf_tag_t *tag, int cid) {
     swf_tag_info_t *tag_info;
-    int tag_no = tag->tag;
+    int tag_no;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_replace_cid: tag == NULL\n");
+        return 1; // failure
+    }
+    tag_no = tag->tag;
     tag_info = get_swf_tag_info(tag_no);
     if (tag_info && tag_info->detail_handler) {
         swf_tag_detail_handler_t * detail_handler = tag_info->detail_handler();
@@ -340,6 +359,10 @@
 
 int
 swf_tag_get_refcid(swf_tag_t *tag) {
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_get_refcid: tag == NULL\n");
+        return -1;
+    }
     if (isPlaceTag(tag->tag)) { // PlaceObject, PlaceObject2
         swf_tag_place_detail_t *swf_tag_place;
         if (! tag->detail) {
@@ -354,6 +377,10 @@
 int
 swf_tag_replace_refcid(swf_tag_t *tag, int cid) {
 //    fprintf(stderr, "XXX: swf_tag_replace_refcid(tag(code=%d), cid(%d))\n", tag->tag, cid);
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_replace_refcid: tag == NULL\n");
+        return 1; // failure
+    }
     if (isPlaceTag(tag->tag)) { // PlaceObject, PlaceObject2
         swf_tag_place_detail_t *swf_tag_place;
         if (! tag->detail) {
@@ -367,7 +394,7 @@
         free(tag->data);
         tag->data = NULL;
     }
-    return 0; // always 0;
+    return 0; // success
 }
 
 /* bitmap */
@@ -380,6 +407,10 @@
         fprintf(stderr, "swf_tag_get_bitmap_size: tag == NULL\n");
         return 1;
     }
+    if ((width == NULL ) || (height == NULL)) {
+        fprintf(stderr, "swf_tag_get_bitmap_size: width == NULL or height == NULL\n");
+        return 1;
+    }
     if (tag->detail == NULL) {
         swf_tag_create_input_detail(tag, NULL);
     }
@@ -392,6 +423,8 @@
         swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) tag->detail;
         *width  = swf_tag_lossless->width;
         *height = swf_tag_lossless->height;
+    } else { // no Bitmap Tag
+        return 1;
     }
     return ret;
 
@@ -400,12 +433,16 @@
 
 unsigned char *
 swf_tag_get_jpeg_data(swf_tag_t *tag, unsigned long *length, int image_id, swf_tag_t *tag_jpegtables) {
-    swf_tag_info_t *tag_info;
+    swf_tag_info_t *tag_info = NULL;
     *length = 0;
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_get_jpeg_data: tag == NULL\n");
         return NULL;
     }
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_get_jpeg_data: length == NULL\n");
+        return NULL;
+    }
     tag_info = get_swf_tag_info(tag->tag);
     if ((tag->tag != 6) && (tag->tag != 21) && (tag->tag != 35)) {
         return NULL;
@@ -434,6 +471,10 @@
         fprintf(stderr, "swf_tag_get_alpha_data: tag == NULL\n");
         return NULL;
     }
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_get_alpha_data: length == NULL\n");
+        return NULL;
+    }
     if (tag->tag != 35) { // ! DefineBitsJPEG3
         return NULL;
     }
@@ -456,13 +497,17 @@
                           unsigned long jpeg_data_len,
                           unsigned char *alpha_data,
                           unsigned long alpha_data_len) {
-    swf_tag_info_t *tag_info;
-    swf_tag_detail_handler_t * detail_handler;
+    swf_tag_info_t *tag_info = NULL;
+    swf_tag_detail_handler_t * detail_handler = NULL;
     int result;
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_replace_jpeg_data: tag == NULL\n");
         return 1;
     }
+    if (jpeg_data == NULL) {
+        fprintf(stderr, "swf_tag_replace_jpeg_data: jpeg_data == NULL\n");
+        return 1;
+    }
     if (! isBitmapTag(tag->tag)) {
         return 1;
     }
@@ -507,12 +552,16 @@
 
 unsigned char *
 swf_tag_get_png_data(swf_tag_t *tag, unsigned long *length, int image_id) {
-    swf_tag_info_t *tag_info;
+    swf_tag_info_t *tag_info = NULL;
     *length = 0;
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_get_png_data: tag == NULL\n");
         return NULL;
     }
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_get_png_data: length == NULL\n");
+        return NULL;
+    }
     tag_info = get_swf_tag_info(tag->tag);
     if ((tag->tag != 20) && (tag->tag != 36)) {
         return NULL;
@@ -531,13 +580,17 @@
 swf_tag_replace_png_data(swf_tag_t *tag, int image_id,
                          unsigned char *png_data,
                          unsigned long png_data_len) {
-    swf_tag_info_t *tag_info;
-    swf_tag_detail_handler_t *detail_handler;
+    swf_tag_info_t *tag_info = NULL;
+    swf_tag_detail_handler_t *detail_handler = NULL;
     int result;
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_replace_png_data: tag == NULL\n");
         return 1;
     }
+    if (png_data == NULL) {
+        fprintf(stderr, "swf_tag_replace_png_data: png_data == NULL\n");
+        return 1;
+    }
     if (! isBitmapTag(tag->tag)) {
         return 1;
     }
@@ -584,13 +637,17 @@
 swf_tag_replace_gif_data(swf_tag_t *tag, int image_id,
                          unsigned char *gif_data,
                          unsigned long gif_data_len) {
-    swf_tag_info_t *tag_info;
-    swf_tag_detail_handler_t *detail_handler;
+    swf_tag_info_t *tag_info = NULL;
+    swf_tag_detail_handler_t *detail_handler = NULL;
     int result;
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_replace_gif_data: tag == NULL\n");
         return 1;
     }
+    if (gif_data == NULL) {
+        fprintf(stderr, "swf_tag_replace_gif_data: gif_data == NULL\n");
+        return 1;
+    }
     if (! isBitmapTag(tag->tag)) {
         return 1;
     }
@@ -637,12 +694,16 @@
 
 unsigned char *
 swf_tag_get_sound_data(swf_tag_t *tag, unsigned long *length, int sound_id) {
-    swf_tag_info_t *tag_info;
+    swf_tag_info_t *tag_info = NULL;
     *length = 0;
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_get_sound_data: tag == NULL\n");
         return NULL;
     }
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_get_sound_data: length == NULL\n");
+        return NULL;
+    }
     tag_info = get_swf_tag_info(tag->tag);
     if (tag->tag != 14) { // DefineSound
         return NULL;
@@ -666,6 +727,10 @@
         fprintf(stderr, "swf_tag_replace_melo_data: tag == NULL\n");
         return 1;
     }
+    if (melo_data == NULL) {
+        fprintf(stderr, "swf_tag_replace_melo_data: melo_data == NULL\n");
+        return 1;
+    }
     if (tag->tag != 14) { // DefineSound
         return 1;
     }
@@ -689,6 +754,7 @@
     return result;
 }
 
+
 char *
 swf_tag_get_edit_string(swf_tag_t *tag,
                         char *variable_name, int variable_name_len,
@@ -697,6 +763,10 @@
         fprintf(stderr, "swf_tag_get_edit_string: tag == NULL\n");
         return NULL;
     }
+    if (variable_name == NULL) {
+        fprintf(stderr, "swf_tag_get_edit_string: variable_name == NULL\n");
+        return NULL;
+    }
     if (tag->tag != 37) { // DefineEditText
         return NULL;
     }
@@ -722,6 +792,10 @@
         fprintf(stderr, "swf_tag_replace_edit_string: tag == NULL\n");
         return 1;
     }
+    if (variable_name == NULL) {
+        fprintf(stderr, "swf_tag_replace_edit_string: variable_name == NULL\n");
+        return 1;
+    }
     if (tag->tag != 37) { // DefineEditText
         return 1;
     }
@@ -744,7 +818,6 @@
     return result;
 }
 
-
 int
 swf_tag_apply_shape_matrix_factor(swf_tag_t *tag, int shape_id,
                                   double scale_x, double scale_y,
@@ -849,13 +922,17 @@
         tag->length = 0;
     }
     return result;
-    
 }
 
 swf_tag_t *
 swf_tag_create_action_setvariables(y_keyvalue_t *kv) {
     int ret;
-    swf_tag_t *tag = calloc(sizeof(*tag), 1);
+    swf_tag_t *tag = NULL;
+    if (kv == NULL) {
+        fprintf(stderr, "swf_tag_create_action_setvariables: kv == NULL\n");
+        return NULL;
+    }
+    tag = calloc(sizeof(*tag), 1);
     tag->tag = 12; // DoAction
     swf_tag_info_t *tag_info = get_swf_tag_info(tag->tag);
     swf_tag_detail_handler_t *detail_handler = tag_info->detail_handler();
@@ -872,6 +949,14 @@
 swf_tag_put_action_setvariables(swf_tag_t *tag, y_keyvalue_t *kv,
                                 struct swf_object_ *swf) {
     int ret;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_put_action_setvariables: tag == NULL\n");
+        return 1;
+    }
+    if (kv == NULL) {
+        fprintf(stderr, "swf_tag_put_action_setvariables: kv == NULL\n");
+        return 1;
+    }
     if (! tag->detail) {
         swf_tag_create_input_detail(tag, swf);
     }
@@ -888,7 +973,12 @@
 }
 
 extern swf_tag_t * swf_tag_move(swf_tag_t *from_tag) {
-    swf_tag_t *to_tag = calloc(sizeof(*to_tag), 1);
+    swf_tag_t *to_tag = NULL;
+    if (from_tag == NULL) {
+        fprintf(stderr, "swf_tag_move: from_tag == NULL\n");
+        return NULL;
+    }
+    to_tag = calloc(sizeof(*to_tag), 1);
     to_tag->tag = from_tag->tag;
     to_tag->length = from_tag->length;
     to_tag->length_longformat = from_tag->length_longformat;

Modified: trunk/src/swf_tag_jpeg.c
===================================================================
--- trunk/src/swf_tag_jpeg.c	2011-03-10 13:01:44 UTC (rev 407)
+++ trunk/src/swf_tag_jpeg.c	2011-03-10 13:15:53 UTC (rev 408)
@@ -73,11 +73,18 @@
 int
 swf_tag_jpeg_input_detail(swf_tag_t *tag,
                           struct swf_object_ *swf) {
-    swf_tag_jpeg_detail_t *swf_tag_jpeg = tag->detail;
-    unsigned char *data  = tag->data;
-    unsigned long length = tag->length;
-    bitstream_t *bs;
+    swf_tag_jpeg_detail_t *swf_tag_jpeg = NULL;
+    unsigned char *data = NULL;
+    unsigned long length;
+    bitstream_t *bs = NULL;
     (void) swf;
+    if (tag == NULL) {
+        fprintf(stderr, "ERROR: swf_tag_jpeg_input_detail: swf_tag_jpeg == NULL\n");
+        return 1;
+    }
+    swf_tag_jpeg = tag->detail;
+    data  = tag->data;
+    length = tag->length;
     if (swf_tag_jpeg == NULL) {
         fprintf(stderr, "ERROR: swf_tag_jpeg_input_detail: swf_tag_jpeg == NULL\n");
         return 1;
@@ -96,10 +103,17 @@
 int
 swf_tag_jpegt_input_detail(swf_tag_t *tag,
                           struct swf_object_ *swf) {
-    swf_tag_jpeg_detail_t *swf_tag_jpeg = tag->detail;
-    unsigned char *data  = tag->data;
-    unsigned long length = tag->length;
+    swf_tag_jpeg_detail_t *swf_tag_jpeg = NULL;
+    unsigned char *data  = NULL;
+    unsigned long length;
     (void) swf;
+    if (tag == NULL) {
+        fprintf(stderr, "ERROR: swf_tag_jpegt_input_detail: tag == NULL\n");
+        return 1;
+    }
+    swf_tag_jpeg = tag->detail;
+    data  = tag->data;
+    length = tag->length;
     if (swf_tag_jpeg == NULL) {
         fprintf(stderr, "ERROR: swf_tag_jpegt_input_detail: swf_tag_jpeg == NULL\n");
         return 1;
@@ -116,16 +130,23 @@
 int
 swf_tag_jpeg3_input_detail(swf_tag_t *tag,
                            struct swf_object_ *swf) {
-    swf_tag_jpeg_detail_t *swf_tag_jpeg = tag->detail;
-    unsigned char *data  = tag->data;
-    unsigned long length = tag->length;
+    swf_tag_jpeg_detail_t *swf_tag_jpeg = NULL;
+    unsigned char *data = NULL;
+    unsigned long length;
     unsigned long offset_to_alpha;
-    bitstream_t *bs;
+    bitstream_t *bs = NULL;
     unsigned long  offset, alpha_data_len;
-    unsigned char *old_buff_ref, *new_buff;
+    unsigned char *old_buff_ref = NULL, *new_buff = NULL;
     unsigned long origsize;
     int result;
     (void) swf;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_jpeg3_input_detail: tag == NULL\n");
+        return 1;
+    }
+    swf_tag_jpeg = tag->detail;
+    data  = tag->data;
+    length = tag->length;
     if (swf_tag_jpeg == NULL) {
         fprintf(stderr, "ERROR: swf_tag_jpeg3_input_detail: swf_tag_jpeg == NULL\n");
         return 1;
@@ -178,7 +199,13 @@
 
 int
 swf_tag_jpeg_get_cid_detail(swf_tag_t *tag) {
-    unsigned char *data = tag->data;
+    unsigned char *data = NULL;
+
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_jpeg_get_cid_detail: tag == NULL\n");
+        return -1;
+    }
+    data = tag->data;
     if (tag->detail) {
         swf_tag_jpeg_detail_t *swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;        
         return swf_tag_jpeg->image_id;
@@ -191,7 +218,12 @@
 }
 int
 swf_tag_jpeg_replace_cid_detail(swf_tag_t *tag, int image_id) {
-    unsigned char *data = tag->data;
+    unsigned char *data = NULL;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_jpeg_replace_cid_detail: tag == NULL\n");
+        return 1;
+    }
+    data = tag->data;
     if (tag->detail) {
         swf_tag_jpeg_detail_t *swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;        
         swf_tag_jpeg->image_id = image_id;
@@ -199,15 +231,20 @@
     if (data) {
         PutUShortLE(data, image_id);
     }
-    return 0; // always 0
+    return 0;
 }
 unsigned char *
 swf_tag_jpeg_output_detail(swf_tag_t *tag, unsigned long *length,
                            struct swf_object_ *swf) {
-    swf_tag_jpeg_detail_t *swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
-    bitstream_t *bs;
-    unsigned char *data;
+    swf_tag_jpeg_detail_t *swf_tag_jpeg = NULL;
+    bitstream_t *bs = NULL;
+    unsigned char *data = NULL;
     (void) swf;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_jpeg_output_detail: tag == NULL\n");
+        return NULL;
+    }
+    swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
     *length = 0;
     bs = bitstream_open();
     bitstream_putbytesLE(bs, swf_tag_jpeg->image_id, 2);
@@ -220,11 +257,20 @@
 unsigned char *
 swf_tag_jpegt_output_detail(swf_tag_t *tag, unsigned long *length,
                             struct swf_object_ *swf) {
-    swf_tag_jpeg_detail_t *swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
-    bitstream_t *bs;
-    unsigned char *data;
+    swf_tag_jpeg_detail_t *swf_tag_jpeg = NULL;
+    bitstream_t *bs = NULL;
+    unsigned char *data = NULL;
     (void) swf;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_jpegt_output_detail: tag == NULL\n");
+        return NULL;
+    }
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_jpegt_output_detail: length == NULL\n");
+        return NULL;
+    }
     *length = 0;
+    swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
     bs = bitstream_open();
     bitstream_putstring(bs, swf_tag_jpeg->jpeg_data, swf_tag_jpeg->jpeg_data_len);
     data = bitstream_steal(bs, length);
@@ -235,13 +281,20 @@
 unsigned char *
 swf_tag_jpeg3_output_detail(swf_tag_t *tag, unsigned long *length,
                             struct swf_object_ *swf) {
-    swf_tag_jpeg_detail_t *swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
-    bitstream_t *bs;
-    unsigned char *data, *new_buff;
+    swf_tag_jpeg_detail_t *swf_tag_jpeg = NULL;
+    bitstream_t *bs = NULL;
+    unsigned char *data = NULL, *new_buff = NULL;
     unsigned long offset_to_alpha;
     unsigned long compsize, old_size;
     int result;
     (void) swf;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_jpeg3_output_detail: tag == NULL\n");
+    }
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_jpeg3_output_detail: length == NULL\n");
+    }
+    swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
     *length = 0;
     bs = bitstream_open();
     bitstream_putbytesLE(bs, swf_tag_jpeg->image_id, 2);
@@ -274,14 +327,20 @@
 void
 swf_tag_jpeg_print_detail(swf_tag_t *tag,
                           struct swf_object_ *swf, int indent_depth) {
-    swf_tag_jpeg_detail_t *swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
-    jpeg_segment_t *jpeg_seg;
-    jpeg_segment_node_t *node;
+    swf_tag_jpeg_detail_t *swf_tag_jpeg = NULL;
+    jpeg_segment_t *jpeg_seg = NULL;
+    jpeg_segment_node_t *node = NULL;
     (void) swf;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_jpeg_print_detail: tag == NULL\n");
+        return ;
+    }
+    swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
     if (swf_tag_jpeg == NULL) {
         fprintf(stderr, "swf_tag_jpeg_print_detail: swf_tag_jpeg == NULL\n");
         return ;
     }
+        
     print_indent(indent_depth);
     if (swf_tag_jpeg->image_id == -1) {
         printf("jpeg_data_size=%lu\n", swf_tag_jpeg->jpeg_data_len);
@@ -322,7 +381,12 @@
 
 void
 swf_tag_jpeg_destroy_detail(swf_tag_t *tag) {
-    swf_tag_jpeg_detail_t *swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
+    swf_tag_jpeg_detail_t *swf_tag_jpeg = NULL;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_jpeg_destroy_detail: tag == NULL\n");
+        return ;
+    }
+    swf_tag_jpeg = (swf_tag_jpeg_detail_t *) tag->detail;
     if (swf_tag_jpeg) {
         free(swf_tag_jpeg->jpeg_data);
         free(swf_tag_jpeg->alpha_data);
@@ -341,10 +405,13 @@
                                           unsigned long jpeg_table_data_len) {
     swf_tag_jpeg_detail_t *swf_tag_jpeg = (swf_tag_jpeg_detail_t *) detail;
     unsigned char *data;
-    *length = 0;
     if (detail == NULL) {
         fprintf(stderr, "swf_tag_jpeg_get_jpeg_data: detail == NULL\n");
     }
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_jpeg_get_jpeg_data: length == NULL\n");
+    }
+    *length = 0;
     if (swf_tag_jpeg->image_id != image_id) {
         return NULL;
     }
@@ -362,12 +429,17 @@
 
 unsigned char *swf_tag_jpeg_get_alpha_data(void *detail, unsigned long *length, int image_id) {
     swf_tag_jpeg_detail_t *swf_tag_jpeg = (swf_tag_jpeg_detail_t *) detail;
-    unsigned char *data;
-    *length = 0;
+    unsigned char *data = NULL;
     if (detail == NULL) {
         fprintf(stderr, "swf_tag_jpeg_get_alpha_data: detail == NULL\n");
         return NULL;
     }
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_jpeg_get_alpha_data: length == NULL\n");
+        return NULL;
+    }
+
+    *length = 0;
     if (swf_tag_jpeg->image_id != image_id) {
         return NULL;
     }

Modified: trunk/src/swf_tag_lossless.c
===================================================================
--- trunk/src/swf_tag_lossless.c	2011-03-10 13:01:44 UTC (rev 407)
+++ trunk/src/swf_tag_lossless.c	2011-03-10 13:15:53 UTC (rev 408)
@@ -51,19 +51,26 @@
 int
 swf_tag_lossless_input_detail(swf_tag_t *tag,
                               struct swf_object_ *swf) {
-    swf_tag_lossless_detail_t *swf_tag_lossless = tag->detail;
-    unsigned char *data  = tag->data;
-    unsigned long length = tag->length;
-    bitstream_t *bs, *bs2;
-    (void) swf;
+    swf_tag_lossless_detail_t *swf_tag_lossless = NULL;
+    unsigned char *data = NULL;
+    unsigned long length;
+    bitstream_t *bs = NULL, *bs2 = NULL;
     unsigned long i;
-    unsigned char *tmp_buff, *old_buff_ref;
+    unsigned char *tmp_buff = NULL, *old_buff_ref = NULL;
     unsigned long origsize, old_size, offset;
     int result;
-    if (swf_tag_lossless == NULL) {
-        fprintf(stderr, "swf_tag_lossless_input_detail: swf_tag_lossless == NULL\n");
+    (void) swf;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_lossless_input_detail: tag == NULL\n");
         return 1;
     }
+    if (tag->detail == NULL) {
+        fprintf(stderr, "swf_tag_lossless_input_detail: tag->detail== NULL\n");
+        return 1;
+    }
+    swf_tag_lossless = tag->detail;
+    data = tag->data;
+    length = tag->length;
 
     bs = bitstream_open();
     bitstream_input(bs, data, length);
@@ -178,7 +185,12 @@
 
 int
 swf_tag_lossless_get_cid_detail(swf_tag_t *tag) {
-    unsigned char *data = tag->data;
+    unsigned char *data = NULL;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_lossless_get_cid_detail: tag == NULL\n");
+        return 1;
+    }
+    data = tag->data;
     if (tag->detail) {
         swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) tag->detail;
         return swf_tag_lossless->image_id;
@@ -192,7 +204,12 @@
 
 int
 swf_tag_lossless_replace_cid_detail(swf_tag_t *tag, int id) {
-    unsigned char *data = tag->data;
+    unsigned char *data = NULL;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_lossless_replace_cid_detail: tag == NULL\n");
+        return 1;
+    }
+    data = tag->data;
     if (tag->detail) {
         swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) tag->detail;
         swf_tag_lossless->image_id = id;
@@ -207,13 +224,22 @@
 swf_tag_lossless_output_detail(swf_tag_t *tag, unsigned long *length,
                                struct swf_object_ *swf) {
     swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) tag->detail;
-    bitstream_t *bs, *bs2;
-    unsigned char *data;
+    bitstream_t *bs = NULL, *bs2 = NULL;
+    unsigned char *data = NULL;
     unsigned long i;
-    unsigned char *tmp_buff, *old_buff_ref;
+    unsigned char *tmp_buff = NULL, *old_buff_ref = NULL;
     unsigned long compsize, old_size;
     int result;
     (void) swf;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_lossless_output_detail: tag == NULL\n");
+        return NULL;
+    }
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_lossless_output_detail: length == NULL\n");
+        return NULL;
+    }
+
     *length = 0;
     bs = bitstream_open();
     bitstream_putbytesLE(bs, swf_tag_lossless->image_id, 2);
@@ -305,12 +331,17 @@
 void
 swf_tag_lossless_print_detail(swf_tag_t *tag,
                               struct swf_object_ *swf, int indent_depth) {
-    swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) tag->detail;
+    swf_tag_lossless_detail_t *swf_tag_lossless = NULL;
     (void) swf;
-    if (swf_tag_lossless == NULL) {
-        fprintf(stderr, "swf_tag_lossless_print_detail: swf_tag_lossless == NULL\n");
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_lossless_print_detail: tag == NULL\n");
         return ;
     }
+    if (tag->detail == NULL) {
+        fprintf(stderr, "swf_tag_lossless_print_detail: tag->detail == NULL\n");
+        return ;
+    }
+    swf_tag_lossless = (swf_tag_lossless_detail_t *) tag->detail;
     print_indent(indent_depth);
     printf("image_id=%d  format=%d  width=%u  height=%u\n",
            swf_tag_lossless->image_id, swf_tag_lossless->format,
@@ -342,7 +373,12 @@
 
 void
 swf_tag_lossless_destroy_detail(swf_tag_t *tag) {
-    swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) tag->detail;
+    swf_tag_lossless_detail_t *swf_tag_lossless;
+    if (tag == NULL) {
+        fprintf(stderr, "swf_tag_lossless_destroy_detail: tag == NULL\n");
+        return ;
+    }
+    swf_tag_lossless = (swf_tag_lossless_detail_t *) tag->detail;
     if (swf_tag_lossless) {
         free(swf_tag_lossless->colormap);
         free(swf_tag_lossless->colormap2);
@@ -363,18 +399,22 @@
 #ifdef HAVE_PNG
 
 unsigned char *swf_tag_lossless_get_png_data(void *detail,
-                                          unsigned long *length,
+                                             unsigned long *length,
                                              int image_id,
                                              swf_tag_t *tag) {
-    swf_tag_lossless_detail_t *swf_tag_lossless;
-    unsigned char *data;
+    swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) detail;
+    unsigned char *data = NULL;
     *length = 0;
     void *index_data = NULL;
     void *image_data = NULL;
     if (detail == NULL) {
         fprintf(stderr, "swf_tag_lossless_get_lossless_data: detail == NULL at line(%d)\n", __LINE__);
+        return NULL;
     }
-    swf_tag_lossless = (swf_tag_lossless_detail_t *) detail;
+    if (length == NULL) {
+        fprintf(stderr, "swf_tag_lossless_get_lossless_data: length == NULL at line(%d)\n", __LINE__);
+        return NULL;
+    }
     if (swf_tag_lossless->image_id != image_id) {
         return NULL;
     }
@@ -418,7 +458,7 @@
                                   unsigned long png_data_len, swf_tag_t *tag) {
     int tag_no, format;
     unsigned short width, height;
-    unsigned char *result_data;
+    unsigned char *result_data = NULL;
     void *colormap = NULL;
     int colormap_count = 0;
     swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) detail;
@@ -426,6 +466,10 @@
         fprintf(stderr, "swf_tag_lossess_replace_png_data: detail == NULL at line(%d)\n", __LINE__);
         return 1;
     }
+    if (png_data == NULL) {
+        fprintf(stderr, "swf_tag_lossess_replace_png_data: png_data == NULL at line(%d)\n", __LINE__);
+        return 1;
+    }
     swf_tag_lossless->image_id = image_id;
     result_data = pngconv_png2lossless(png_data, png_data_len,
                                        &tag_no, &format,
@@ -497,7 +541,7 @@
                                   unsigned long gif_data_len, swf_tag_t *tag) {
     int tag_no, format;
     unsigned short width, height;
-    unsigned char *result_data;
+    unsigned char *result_data = NULL;
     void *colormap = NULL;
     int colormap_count = 0;
     swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) detail;
@@ -505,6 +549,10 @@
         fprintf(stderr, "swf_tag_lossless_replace_gif_data: detail == NULL at line(%d)\n", __LINE__);
         return 1;
     }
+    if (gif_data == NULL) {
+        fprintf(stderr, "swf_tag_lossless_replace_gif_data: gif_data == NULL at line(%d)\n", __LINE__);
+        return 1;
+    }
     swf_tag_lossless->image_id = image_id;
     result_data = gifconv_gif2lossless(gif_data, gif_data_len,
                                        &tag_no, &format,



Swfed-svn メーリングリストの案内
Back to archive index