4935337
From c62cadc78de1ee69ca3643441477b779d0a817e4 Mon Sep 17 00:00:00 2001
4935337
From: Remi Collet <remi@php.net>
4935337
Date: Mon, 6 Apr 2015 10:30:12 +0200
4935337
Subject: [PATCH] PHP 7 compatibility
4935337
4935337
---
4935337
 php_ssdeep.h |  9 +++++++++
4935337
 ssdeep.c     | 22 +++++++++++++---------
4935337
 2 files changed, 22 insertions(+), 9 deletions(-)
4935337
4935337
diff --git a/php_ssdeep.h b/php_ssdeep.h
4935337
index 5deaa40..9a88de0 100644
4935337
--- a/php_ssdeep.h
4935337
+++ b/php_ssdeep.h
4935337
@@ -47,4 +47,13 @@
4935337
 
4935337
     extern zend_module_entry php_ssdeep_module_entry;
4935337
 #   define phpext_php_ssdeep_ptr &php_ssdeep_module_entry
4935337
+
4935337
+#if PHP_MAJOR_VERSION < 7
4935337
+typedef int strsize_t;
4935337
+#define _RETURN_STRING(s)  RETURN_STRING(s, 0);
4935337
+#else
4935337
+typedef size_t strsize_t;
4935337
+#define _RETURN_STRING(s)  { RETVAL_STRING(s); efree(s); return; }
4935337
+#endif
4935337
+
4935337
 #endif
4935337
diff --git a/ssdeep.c b/ssdeep.c
4935337
index 3cae212..81f4e07 100644
4935337
--- a/ssdeep.c
4935337
+++ b/ssdeep.c
4935337
@@ -67,8 +67,12 @@ ZEND_END_ARG_INFO()
4935337
 const zend_function_entry ssdeep_functions[] = {
4935337
     PHP_FE(ssdeep_fuzzy_hash, arginfo_ssdeep_fuzzy_hash)
4935337
     PHP_FE(ssdeep_fuzzy_hash_filename, arginfo_ssdeep_fuzzy_hash_filename)
4935337
-    PHP_FE(ssdeep_fuzzy_compare, arginfo_ssdeep_fuzzy_compare) {
4935337
-        NULL, NULL, NULL} /* Must be the last line in ssdeep_functions[] */
4935337
+    PHP_FE(ssdeep_fuzzy_compare, arginfo_ssdeep_fuzzy_compare)
4935337
+#ifdef PHP_FE_END
4935337
+    PHP_FE_END
4935337
+#else
4935337
+    { NULL, NULL, NULL } /* Must be the last line in ssdeep_functions[] */
4935337
+#endif
4935337
 };
4935337
 /* }}} */
4935337
 
4935337
@@ -101,16 +105,16 @@ PHP_MINFO_FUNCTION(ssdeep) {
4935337
 PHP_FUNCTION(ssdeep_fuzzy_hash) {
4935337
     char *hash = (char *) emalloc(FUZZY_MAX_RESULT);
4935337
     char *to_hash;
4935337
-    int to_hash_len;
4935337
+    strsize_t to_hash_len;
4935337
 
4935337
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &to_hash, &to_hash_len) == FAILURE) {
4935337
         RETURN_NULL();
4935337
     }
4935337
 
4935337
-    if (0 != fuzzy_hash_buf((unsigned char *) to_hash, to_hash_len, hash)) {
4935337
+    if (0 != fuzzy_hash_buf((unsigned char *) to_hash, (uint32_t)to_hash_len, hash)) {
4935337
         RETURN_FALSE;
4935337
     } else {
4935337
-        RETURN_STRING(hash, 0);
4935337
+        _RETURN_STRING(hash);
4935337
     }
4935337
 }
4935337
 /* }}} */
4935337
@@ -120,7 +124,7 @@ PHP_FUNCTION(ssdeep_fuzzy_hash) {
4935337
 PHP_FUNCTION(ssdeep_fuzzy_hash_filename) {
4935337
     char *hash = (char *) emalloc(FUZZY_MAX_RESULT);
4935337
     char *file_name;
4935337
-    int file_name_len;
4935337
+    strsize_t file_name_len;
4935337
 
4935337
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &file_name_len) == FAILURE) {
4935337
         RETURN_NULL();
4935337
@@ -129,7 +133,7 @@ PHP_FUNCTION(ssdeep_fuzzy_hash_filename) {
4935337
     if (0 != fuzzy_hash_filename(file_name, hash)) {
4935337
         RETURN_FALSE;
4935337
     } else {
4935337
-        RETURN_STRING(hash, 0);
4935337
+        _RETURN_STRING(hash);
4935337
     }
4935337
 }
4935337
 /* }}} */
4935337
@@ -138,9 +142,9 @@ PHP_FUNCTION(ssdeep_fuzzy_hash_filename) {
4935337
  */
4935337
 PHP_FUNCTION(ssdeep_fuzzy_compare) {
4935337
     char *signature1 = NULL;
4935337
-    int signature1_len;
4935337
+    strsize_t signature1_len;
4935337
     char *signature2 = NULL;
4935337
-    int signature2_len;
4935337
+    strsize_t signature2_len;
4935337
     int match;
4935337
     
4935337
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &signature1, &signature1_len, &signature2, &signature2_len) == FAILURE) {
4935337
-- 
4935337
2.1.0
4935337