From: Xinchen Hui Date: Fri, 12 Aug 2011 07:47:03 +0000 (+0000) Subject: Omitted GCC warning "comparison is always false" X-Git-Tag: php-5.4.0beta1~439 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba9546b8e5a9d4110d2ff1bc03a3ccf49d7a5490;p=php Omitted GCC warning "comparison is always false" --- diff --git a/ext/ereg/ereg.c b/ext/ereg/ereg.c index c2b065210a..0dd6845d62 100644 --- a/ext/ereg/ereg.c +++ b/ext/ereg/ereg.c @@ -474,7 +474,8 @@ PHP_EREG_API char *php_ereg_replace(const char *pattern, const char *replace, co if (new_l + 1 > buf_len) { buf_len = 1 + buf_len + 2 * new_l; nbuf = emalloc(buf_len); - strncpy(nbuf, buf, buf_len-1); + strncpy(nbuf, buf, buf_len - 1); + nbuf[buf_len - 1] = '\0'; efree(buf); buf = nbuf; } @@ -486,7 +487,7 @@ PHP_EREG_API char *php_ereg_replace(const char *pattern, const char *replace, co walkbuf = &buf[tmp + subs[0].rm_so]; walk = replace; while (*walk) { - if ('\\' == *walk && isdigit(walk[1]) && walk[1] - '0' <= (int)re.re_nsub) { + if ('\\' == *walk && isdigit((unsigned char)walk[1]) && (unsigned char)walk[1] - '0' <= (int)re.re_nsub) { if (subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1 /* this next case shouldn't happen. it does. */ && subs[walk[1] - '0'].rm_so <= subs[walk[1] - '0'].rm_eo) { diff --git a/ext/ereg/regex/regerror.c b/ext/ereg/regex/regerror.c index 1c66d4114e..7bf741967d 100644 --- a/ext/ereg/regex/regerror.c +++ b/ext/ereg/regex/regerror.c @@ -82,10 +82,12 @@ size_t errbuf_size) break; if (errcode®_ITOA) { - if (r->code >= 0) - (void) strncpy(convbuf, r->name, 50); - else + if (r->code >= 0) { + (void) strncpy(convbuf, r->name, sizeof(convbuf) - 1); + convbuf[sizeof(convbuf) - 1] = '\0'; + } else { snprintf(convbuf, sizeof(convbuf), "REG_0x%x", target); + } assert(strlen(convbuf) < sizeof(convbuf)); s = convbuf; } else diff --git a/ext/standard/var.c b/ext/standard/var.c index cf9342db4f..404504a1f3 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -601,7 +601,7 @@ static inline zend_bool php_var_serialize_class_name(smart_str *buf, zval *struc PHP_SET_CLASS_ATTRIBUTES(struc); smart_str_appendl(buf, "O:", 2); - smart_str_append_long(buf, (long)name_len); + smart_str_append_long(buf, (int)name_len); smart_str_appendl(buf, ":\"", 2); smart_str_appendl(buf, class_name, name_len); smart_str_appendl(buf, "\":", 2); @@ -767,12 +767,12 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, HashTable *var if (ce->serialize(struc, &serialized_data, &serialized_length, (zend_serialize_data *)var_hash TSRMLS_CC) == SUCCESS) { smart_str_appendl(buf, "C:", 2); - smart_str_append_long(buf, (long)Z_OBJCE_P(struc)->name_length); + smart_str_append_long(buf, (int)Z_OBJCE_P(struc)->name_length); smart_str_appendl(buf, ":\"", 2); smart_str_appendl(buf, Z_OBJCE_P(struc)->name, Z_OBJCE_P(struc)->name_length); smart_str_appendl(buf, "\":", 2); - smart_str_append_long(buf, (long)serialized_length); + smart_str_append_long(buf, (int)serialized_length); smart_str_appendl(buf, ":{", 2); smart_str_appendl(buf, serialized_data, serialized_length); smart_str_appendc(buf, '}'); diff --git a/main/streams/cast.c b/main/streams/cast.c index debbd82707..38eb1a987c 100644 --- a/main/streams/cast.c +++ b/main/streams/cast.c @@ -271,7 +271,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show newstream = php_stream_fopen_tmpfile(); if (newstream) { - int retval = php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL, NULL); + size_t retval = php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL, NULL); if (ret != SUCCESS) { php_stream_close(newstream);