summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-10-10 11:12:17 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-10-10 11:13:10 +0200
commit6878c583b02b75aeab84c493d548700fb1de5976 (patch)
tree07d7fbfef85d73ebedde5769df7ab09070de25f5 /main
parent382f9b28e8390a49137fc028a0c04d291781ae7a (diff)
downloadphp-git-6878c583b02b75aeab84c493d548700fb1de5976.tar.gz
Report error if stream_read is not implemented
We need to return -1 in this case. Slightly restructure the code to avoid unnecessary conditions.
Diffstat (limited to 'main')
-rw-r--r--main/streams/userspace.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index de3e8591e6..af7f0b4fa2 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -671,27 +671,28 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
return -1;
}
- if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
- if (Z_TYPE(retval) == IS_FALSE) {
- return -1;
- }
-
- if (!try_convert_to_string(&retval)) {
- return -1;
- }
-
- didread = Z_STRLEN(retval);
- if (didread > count) {
- php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost",
- us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_long)count);
- didread = count;
- }
- if (didread > 0)
- memcpy(buf, Z_STRVAL(retval), didread);
- } else if (call_result == FAILURE) {
+ if (call_result == FAILURE) {
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!",
us->wrapper->classname);
+ return -1;
+ }
+
+ if (Z_TYPE(retval) == IS_FALSE) {
+ return -1;
+ }
+
+ if (!try_convert_to_string(&retval)) {
+ return -1;
+ }
+
+ didread = Z_STRLEN(retval);
+ if (didread > count) {
+ php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost",
+ us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_long)count);
+ didread = count;
}
+ if (didread > 0)
+ memcpy(buf, Z_STRVAL(retval), didread);
zval_ptr_dtor(&retval);
ZVAL_UNDEF(&retval);