From a6efd041641e46f5abcb2fa35000574090c9abf2 Mon Sep 17 00:00:00 2001 From: Yoshihiro Yamazaki Date: Mon, 23 Nov 2015 02:38:52 +0900 Subject: [PATCH] =?utf8?q?RETURN=5FSTRINGL=20=E3=81=A8=20add=5Fassoc=5Fstr?= =?utf8?q?ing=5Fex=20=E3=81=AE=20dup=20=E5=BC=95=E6=95=B0=E5=89=8A?= =?utf8?q?=E9=99=A4=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/php7_swfed.c | 107 +++++++++++++++---------------------------------------- 1 file changed, 28 insertions(+), 79 deletions(-) diff --git a/src/php7_swfed.c b/src/php7_swfed.c index e9fc69f..e7699dc 100644 --- a/src/php7_swfed.c +++ b/src/php7_swfed.c @@ -286,8 +286,7 @@ PHP_FUNCTION(confirm_swfed_compiled) } len = sprintf(string, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "swfed", arg); -// RETURN_STRINGL(string, len, 0); - RETURN_STRINGL(string, len); // dup:1 + RETURN_STRINGL(string, len); } /* }}} */ /* The previous line is meant for vim and emacs, so it can correctly fold and @@ -345,7 +344,6 @@ PHP_METHOD(swfed, input) { PHP_METHOD(swfed, output) { unsigned long len = 0; unsigned char *data = NULL; - char *new_buff = NULL; swf_object_t *swf = NULL; if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; @@ -353,15 +351,9 @@ PHP_METHOD(swfed, output) { } swf = get_swf_object(getThis() TSRMLS_CC); data = swf_object_output(swf, &len); - new_buff = emalloc(len); - if (new_buff == NULL) { - fprintf(stderr, "output: Can't emalloc new_buff\n"); - free(data); - RETURN_FALSE; - } - memcpy(new_buff, data, len); + RETVAL_STRINGL(data, len); free(data); - RETURN_STRINGL(new_buff, len); // dup:0 + return ; } PHP_METHOD(swfed, swfInfo) { @@ -465,7 +457,7 @@ PHP_METHOD(swfed, getTagList) { tag_info = get_swf_tag_info(tag->code); if (tag_info && tag_info->name) { add_assoc_string_ex(data, ZEND_STRL("tagName"), - (char *)tag_info->name); // dup:1 + (char *)tag_info->name); } add_assoc_long(data, "length", tag->length); if (tag_info && tag_info->detail_handler) { @@ -573,11 +565,11 @@ PHP_METHOD(swfed, getTagDetail) { add_assoc_long(return_value, "edit_id", tag_edit->edit_id); if (tag_edit->edit_variable_name && tag_edit->edit_variable_name[0]) { add_assoc_string_ex(return_value, ZEND_STRL("variable_name"), - (char *)tag_edit->edit_variable_name); // dup:1 + (char *)tag_edit->edit_variable_name); } if (tag_edit->edit_initial_text && tag_edit->edit_initial_text[0]) { add_assoc_string_ex(return_value, ZEND_STRL("initial_text"), - (char *)tag_edit->edit_initial_text); // dup:1 + (char *)tag_edit->edit_initial_text); } break; case 39: // DefineSprite; @@ -617,7 +609,7 @@ PHP_METHOD(swfed, getTagDetail) { } add_assoc_long(return_value, "depth", tag_place->depth); if (tag_place->flag_has_name) { - add_assoc_string_ex(return_value, ZEND_STRL("name"), (char *)tag_place->name); // dup:1 + add_assoc_string_ex(return_value, ZEND_STRL("name"), (char *)tag_place->name); } default: @@ -630,7 +622,7 @@ PHP_METHOD(swfed, getTagDetail) { PHP_METHOD(swfed, getTagData) { long tag_seqno = 0; swf_object_t *swf = NULL; - unsigned char *data = NULL, *new_buff; + unsigned char *data = NULL; unsigned long data_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_seqno) == FAILURE) { @@ -642,10 +634,9 @@ PHP_METHOD(swfed, getTagData) { fprintf(stderr, "getTagData: Can't get_tagdata\n"); RETURN_FALSE; } - new_buff = emalloc(data_len); - memcpy(new_buff, data, data_len); + RETVAL_STRINGL(data, data_len); free(data); - RETURN_STRINGL(new_buff, data_len); // dup:0 + return ; } PHP_METHOD(swfed, replaceTagData) { @@ -688,7 +679,7 @@ PHP_METHOD(swfed, getTagDataByCID) { fprintf(stderr, "getTagDataByCID: Can't get_tagdata_bycid\n"); RETURN_FALSE; } - RETURN_STRINGL((char *) data_ref, data_len); // dup:1 + RETURN_STRINGL((char *) data_ref, data_len); } PHP_METHOD(swfed, replaceTagDataByCID) { @@ -731,7 +722,7 @@ PHP_METHOD(swfed, getTagContentsByCID) { fprintf(stderr, "getTagContentsByCID: Can't get_tagcontents_bycid\n"); RETURN_FALSE; } - RETURN_STRINGL((char *)data_ref, data_len); // dup:1 + RETURN_STRINGL((char *)data_ref, data_len); } PHP_METHOD(swfed, replaceTagContentsByCID) { @@ -813,7 +804,7 @@ PHP_METHOD(swfed, printTagData) { PHP_METHOD(swfed, getShapeData) { long cid = 0; swf_object_t *swf = NULL; - unsigned char *data = NULL, *new_buff; + unsigned char *data = NULL; unsigned long data_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &cid) == FAILURE) { RETURN_FALSE; @@ -824,10 +815,9 @@ PHP_METHOD(swfed, getShapeData) { fprintf(stderr, "getShapeData: Can't swf_object_get_shapedata (cid=%ld)\n", cid); RETURN_FALSE; } - new_buff = emalloc(data_len); - memcpy(new_buff, data, data_len); + RETVAL_STRINGL((char *)data, data_len); free(data); - RETURN_STRINGL((char *)new_buff, data_len); // dup:0 + return ; } PHP_METHOD(swfed, replaceShapeData) { @@ -924,7 +914,6 @@ PHP_METHOD(swfed, getJpegData) { unsigned long image_id = 0; unsigned long len = 0; unsigned char *data = NULL; - char *new_buff = NULL; swf_object_t *swf = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &image_id) == FAILURE) { @@ -935,22 +924,15 @@ PHP_METHOD(swfed, getJpegData) { if (data == NULL) { RETURN_FALSE; } - new_buff = emalloc(len); - if (new_buff == NULL) { - fprintf(stderr, "getJpegData Can't emalloc new_buff\n"); - free(data); - RETURN_FALSE; - } - memcpy(new_buff, data, len); + RETVAL_STRINGL(data, (int) len); free(data); - RETURN_STRINGL(new_buff, (int) len); // dup:0 + return ; } PHP_METHOD(swfed, getJpegAlpha) { unsigned long image_id = 0; unsigned long len = 0; unsigned char *data = NULL; - char *new_buff = NULL; swf_object_t *swf = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &image_id) == FAILURE) { @@ -961,15 +943,9 @@ PHP_METHOD(swfed, getJpegAlpha) { if (data == NULL) { RETURN_FALSE; } - new_buff = emalloc(len); - if (new_buff == NULL) { - fprintf(stderr, "getJpegAlpha Can't emalloc new_buff\n"); - free(data); - RETURN_FALSE; - } - memcpy(new_buff, data, len); + RETVAL_STRINGL(data, len); free(data); - RETURN_STRINGL(new_buff, len); // dup:0 + return ; } PHP_METHOD(swfed, replaceJpegData) { @@ -1014,7 +990,6 @@ PHP_METHOD(swfed, getPNGData) { unsigned long image_id = 0; unsigned long len = 0; unsigned char *data = NULL; - char *new_buff = NULL; swf_object_t *swf = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &image_id) == FAILURE) { @@ -1025,15 +1000,9 @@ PHP_METHOD(swfed, getPNGData) { if (data == NULL) { RETURN_FALSE; } - new_buff = emalloc(len); - if (new_buff == NULL) { - fprintf(stderr, "getPNGData: Can't emalloc new_buff\n"); - free(data); - RETURN_FALSE; - } - memcpy(new_buff, data, len); + RETVAL_STRINGL(data, (int) len); free(data); - RETURN_STRINGL(new_buff, (int) len); // dup:0 + return ; #endif /* HAVE_PNG */ } @@ -1310,7 +1279,6 @@ PHP_METHOD(swfed, getSoundData) { unsigned long sound_id = 0; unsigned long len = 0; unsigned char *data = NULL; - char *new_buff = NULL; swf_object_t *swf = NULL; if (param_is_null(1 TSRMLS_CC)) { php_error(E_WARNING, "%s() 1st arg must be not NULL", get_active_function_name(TSRMLS_C)); @@ -1325,15 +1293,9 @@ PHP_METHOD(swfed, getSoundData) { if (data == NULL) { RETURN_FALSE; } - new_buff = emalloc(len); - if (new_buff == NULL) { - fprintf(stderr, "getSoundData: Can't emalloc new_buff\n"); - free(data); - RETURN_FALSE; - } - memcpy(new_buff, data, len); + RETVAL_STRINGL(data, (int) len); free(data); - RETURN_STRINGL(new_buff, (int) len); // dup:0 + return ; } PHP_METHOD(swfed, replaceMLDData) { @@ -1370,7 +1332,7 @@ PHP_METHOD(swfed, getEditString) { char *var_name = NULL; int var_name_len = 0; swf_object_t *swf = NULL; - char *data = NULL, *new_buff = NULL; + char *data = NULL; int str_len = 0; int error = 0; if (param_is_null(1 TSRMLS_CC)) { @@ -1391,15 +1353,9 @@ PHP_METHOD(swfed, getEditString) { } } str_len = strlen(data); - new_buff = emalloc(str_len); - if (new_buff == NULL) { - fprintf(stderr, "getEditString: Can't emalloc new_buff\n"); - free(data); - RETURN_FALSE; - } - memcpy(new_buff, data, str_len); + RETVAL_STRINGL(data, str_len); free(data); - RETURN_STRINGL(new_buff, str_len); // dup:0 + return ; } PHP_METHOD(swfed, replaceEditString) { @@ -1429,7 +1385,6 @@ PHP_METHOD(swfed, getActionData) { long tag_seqno = 0; swf_object_t *swf = NULL; unsigned char *data = NULL; - char *new_buff = NULL; unsigned long data_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_seqno) == FAILURE) { @@ -1441,15 +1396,9 @@ PHP_METHOD(swfed, getActionData) { fprintf(stderr, "getActionData: Can't get_actiondata\n"); RETURN_FALSE; } - new_buff = emalloc(data_len); - if (new_buff == NULL) { - fprintf(stderr, "getActionData: Can't emalloc new_buff\n"); - free(data); - RETURN_FALSE; - } - memcpy(new_buff, data, data_len); + RETVAL_STRINGL(data, data_len); free(data); - RETURN_STRINGL(new_buff, data_len); // dup:0 + return ; } PHP_METHOD(swfed, disasmActionData) { -- 2.11.0