]> granicus.if.org Git - php/commitdiff
tidy up implicit_mode handling; spotted by Nuno
authorWez Furlong <wez@php.net>
Sun, 14 Aug 2005 13:48:29 +0000 (13:48 +0000)
committerWez Furlong <wez@php.net>
Sun, 14 Aug 2005 13:48:29 +0000 (13:48 +0000)
There's probably a much more efficient way to do this than the current strchr stuff.

main/streams/streams.c

index a976ff967a701d50ff921e459ec0ac6e490bf976..c447f447895a2e3069ab0a785fd38656dd7cb932 100755 (executable)
@@ -2347,7 +2347,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
        char *path_to_open;
        int persistent = options & STREAM_OPEN_PERSISTENT;
        char *copy_of_path = NULL;
-       int implicit_mode[16];
+       char implicit_mode[16];
        int modelen = strlen(mode);
        
        if (opened_path) {
@@ -2366,20 +2366,20 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
                return NULL;
        }
 
-       memcpy(implicit_mode, mode, modelen);
+       strlcpy(implicit_mode, mode, sizeof(implicit_mode));
        if (context && context->default_mode && modelen < 15 && !strchr(mode, 't') && !strchr(mode, 'b')) {
                if (context->default_mode & PHP_FILE_BINARY) {
                        implicit_mode[modelen++] = 'b';
                } else if (context->default_mode & PHP_FILE_TEXT) {
                        implicit_mode[modelen++] = 't';
                }
-               implicit_mode[modelen] = 0;
+               implicit_mode[modelen] = '\0';
        }
 
        if (wrapper) {
 
                stream = wrapper->wops->stream_opener(wrapper,
-                               path_to_open, (char *)implicit_mode, options ^ REPORT_ERRORS,
+                               path_to_open, implicit_mode, options ^ REPORT_ERRORS,
                                opened_path, context STREAMS_REL_CC TSRMLS_CC);
 
                /* if the caller asked for a persistent stream but the wrapper did not
@@ -2393,7 +2393,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
                
                if (stream) {
                        stream->wrapper = wrapper;
-                       memcpy(stream->mode, implicit_mode, modelen + 1);
+                       strlcpy(stream->mode, implicit_mode, sizeof(stream->mode));
                }
        }
 
@@ -2441,7 +2441,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
        }
 
        /* Output encoding on text mode streams defaults to utf8 unless specified in context parameter */
-       if (stream && memchr(implicit_mode, 't', modelen) && (memchr(implicit_mode, 'w', modelen) || memchr(implicit_mode, 'a', modelen) || memchr(implicit_mode, '+', modelen))) {
+       if (stream && strchr(implicit_mode, 't') && (strchr(implicit_mode, 'w') || strchr(implicit_mode, 'a') || strchr(implicit_mode, '+'))) {
                php_stream_filter *filter;
                char *encoding = (context && context->output_encoding) ? context->output_encoding : "utf8";
                char *filtername;
@@ -2460,7 +2460,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
                efree(filtername);
        }
 
-       if (stream && memchr(implicit_mode, 't', modelen) && (memchr(implicit_mode, 'r', modelen) || memchr(implicit_mode, '+', modelen))) {
+       if (stream && strchr(implicit_mode, 't') && (strchr(implicit_mode, 'r') || strchr(implicit_mode, '+'))) {
                php_stream_filter *filter;
                char *filtername;
                char *encoding = (context && context->input_encoding) ? context->input_encoding : "utf8";