Skip to content

Commit fab79f4

Browse files
committed
Handle null strings
1 parent 95416a9 commit fab79f4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

php/ext/google/protobuf/convert.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ static bool buftoint64(const char* ptr, const char* end, int64_t* val) {
211211
}
212212

213213
static void throw_conversion_exception(const char* to, const zval* zv) {
214+
if (Z_TYPE_P(zv) == IS_NULL) {
215+
zend_throw_exception_ex(NULL, 0, "Cannot convert NULL to %s", to);
216+
return;
217+
}
218+
214219
zval tmp;
215220
ZVAL_COPY(&tmp, zv);
216221
convert_to_string(&tmp);
@@ -370,7 +375,12 @@ bool Convert_PhpToUpb(zval* php_val, upb_MessageValue* upb_val, TypeInfo type,
370375
return to_bool(php_val, &upb_val->bool_val);
371376
case kUpb_CType_String:
372377
case kUpb_CType_Bytes: {
373-
if (!to_string(php_val)) return false;
378+
if (Z_TYPE_P(php_val) == IS_NULL) {
379+
upb_val->str_val = upb_StringView_FromDataAndSize(NULL, 0);
380+
return true;
381+
} else if (!to_string(php_val)) {
382+
return false;
383+
}
374384

375385
char* ptr = Z_STRVAL_P(php_val);
376386
size_t size = Z_STRLEN_P(php_val);

0 commit comments

Comments
 (0)