iliaa Sat Jan 18 13:32:21 2003 EDT
Modified files:
/php4/ext/exif exif.c
Log:
Removed the no longer needed memory allocation checks.
Index: php4/ext/exif/exif.c
diff -u php4/ext/exif/exif.c:1.137 php4/ext/exif/exif.c:1.138
--- php4/ext/exif/exif.c:1.137 Tue Dec 31 11:06:32 2002
+++ php4/ext/exif/exif.c Sat Jan 18 13:32:19 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: exif.c,v 1.137 2002/12/31 16:06:32 sebastian Exp $ */
+/* $Id: exif.c,v 1.138 2003/01/18 18:32:19 iliaa Exp $ */
/* ToDos
*
@@ -95,7 +95,7 @@
};
/* }}} */
-#define EXIF_VERSION "1.4 $Id: exif.c,v 1.137 2002/12/31 16:06:32 sebastian Exp $"
+#define EXIF_VERSION "1.4 $Id: exif.c,v 1.138 2003/01/18 18:32:19 iliaa Exp $"
/* {{{ PHP_MINFO_FUNCTION
*/
@@ -234,17 +234,13 @@
/* {{{ error messages
*/
-static const char * EXIF_ERROR_EALLOC = "Cannot allocate memory for all data";
static const char * EXIF_ERROR_FILEEOF = "Unexpected end of file reached";
static const char * EXIF_ERROR_CORRUPT = "File structure corrupted";
static const char * EXIF_ERROR_THUMBEOF = "Thumbnail goes IFD boundary or end of
file reached";
-static const char * EXIF_ERROR_FSREALLOC = "Illegal reallocating of undefined file
section";
-#define EXIF_ERRLOG_EALLOC php_error_docref(NULL TSRMLS_CC, E_ERROR,
EXIF_ERROR_EALLOC);
#define EXIF_ERRLOG_FILEEOF php_error_docref(NULL TSRMLS_CC, E_WARNING,
EXIF_ERROR_FILEEOF);
#define EXIF_ERRLOG_CORRUPT php_error_docref(NULL TSRMLS_CC, E_WARNING,
EXIF_ERROR_CORRUPT);
#define EXIF_ERRLOG_THUMBEOF php_error_docref(NULL TSRMLS_CC, E_WARNING,
EXIF_ERROR_THUMBEOF);
-#define EXIF_ERRLOG_FSREALLOC php_error_docref(NULL TSRMLS_CC, E_WARNING,
EXIF_ERROR_FSREALLOC);
/* }}} */
/* {{{ format description defines
@@ -1332,10 +1328,6 @@
len += strlen(exif_get_sectionname(i))+2;
}
sections = emalloc(len+1);
- if (!sections) {
- EXIF_ERRLOG_EALLOC
- return NULL;
- }
sections[0] = '\0';
len = 0;
for(i=0; i<SECTION_COUNT; i++) {
@@ -1468,9 +1460,6 @@
int count = ImageInfo->file.count;
tmp = erealloc(ImageInfo->file.list, (count+1)*sizeof(file_section));
- if (tmp == NULL) {
- return 0;
- }
ImageInfo->file.list = tmp;
ImageInfo->file.list[count].type = 0xFFFF;
ImageInfo->file.list[count].data = NULL;
@@ -1479,9 +1468,7 @@
if (!size) {
data = NULL;
} else if (data == NULL) {
- if ((data = emalloc(size)) == NULL) {
- return -1;
- }
+ data = emalloc(size);
}
ImageInfo->file.list[count].type = type;
ImageInfo->file.list[count].data = data;
@@ -1497,14 +1484,10 @@
{
void *tmp;
- if (section_index >= ImageInfo->file.count) {
- EXIF_ERRLOG_FSREALLOC
- return -1;
- }
- if (!(tmp = erealloc(ImageInfo->file.list[section_index].data, size)) && size)
{
- EXIF_ERRLOG_EALLOC
+ if (size <= 0 || section_index >= ImageInfo->file.count) {
return -1;
}
+ tmp = erealloc(ImageInfo->file.list[section_index].data, size);
ImageInfo->file.list[section_index].data = tmp;
ImageInfo->file.list[section_index].size = size;
return 0;
@@ -1541,10 +1524,6 @@
image_info_data *list;
list = erealloc(image_info->info_list[section_index].list,
(image_info->info_list[section_index].count+1)*sizeof(image_info_data));
- if (!list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
image_info->info_list[section_index].list = list;
info_data =
&image_info->info_list[section_index].list[image_info->info_list[section_index].count];
@@ -1552,10 +1531,6 @@
info_data->format = format;
info_data->length = length;
info_data->name = estrdup(name);
- if (!info_data->name) {
- EXIF_ERRLOG_EALLOC
- return;
- }
info_value = &info_data->value;
switch (format) {
@@ -1572,11 +1547,6 @@
info_data->length = 0;
info_value->s = estrdup("");
}
- if (!info_value->s) {
- EXIF_ERRLOG_EALLOC
- info_data->length = 0;
- break; /* better return with "" instead of possible
causing problems */
- }
break;
default:
@@ -1604,10 +1574,6 @@
info_data->length = 0;
info_value->s = estrdup("");
}
- if (!info_value->s) {
- EXIF_ERRLOG_EALLOC
- return;
- }
break;
case TAG_FMT_USHORT:
@@ -1623,10 +1589,6 @@
} else
if (length>1) {
info_data->value.list =
emalloc(length*sizeof(image_info_value));
- if (!info_data->value.list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
} else {
info_value = &info_data->value;
}
@@ -1699,10 +1661,6 @@
image_info_data *list;
list = erealloc(image_info->info_list[section_index].list,
(image_info->info_list[section_index].count+1)*sizeof(image_info_data));
- if (!list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
image_info->info_list[section_index].list = list;
info_data =
&image_info->info_list[section_index].list[image_info->info_list[section_index].count];
@@ -1710,10 +1668,6 @@
info_data->format = TAG_FMT_SLONG;
info_data->length = 1;
info_data->name = estrdup(name);
- if (!info_data->name) {
- EXIF_ERRLOG_EALLOC
- return;
- }
info_data->value.i = value;
image_info->sections_found |= 1<<section_index;
image_info->info_list[section_index].count++;
@@ -1730,28 +1684,16 @@
if (value) {
list = erealloc(image_info->info_list[section_index].list,
(image_info->info_list[section_index].count+1)*sizeof(image_info_data));
- if (!list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
image_info->info_list[section_index].list = list;
info_data =
&image_info->info_list[section_index].list[image_info->info_list[section_index].count];
info_data->tag = TAG_NONE;
info_data->format = TAG_FMT_STRING;
info_data->length = 1;
info_data->name = estrdup(name);
- if (!info_data->name) {
- EXIF_ERRLOG_EALLOC
- return;
- }
if (PG(magic_quotes_runtime)) {
info_data->value.s = php_addslashes(value, strlen(value),
NULL, 0 TSRMLS_CC);
} else {
info_data->value.s = estrdup(value);
- if (!info_data->value.s) {
- EXIF_ERRLOG_EALLOC
- return;
- }
}
image_info->sections_found |= 1<<section_index;
image_info->info_list[section_index].count++;
@@ -1787,20 +1729,12 @@
if (value) {
list = erealloc(image_info->info_list[section_index].list,
(image_info->info_list[section_index].count+1)*sizeof(image_info_data));
- if (!list) {
- EXIF_ERRLOG_EALLOC
- return;
- }
image_info->info_list[section_index].list = list;
info_data =
&image_info->info_list[section_index].list[image_info->info_list[section_index].count];
info_data->tag = TAG_NONE;
info_data->format = TAG_FMT_UNDEFINED;
info_data->length = length;
info_data->name = estrdup(name);
- if (!info_data->name) {
- EXIF_ERRLOG_EALLOC
- return;
- }
if (PG(magic_quotes_runtime)) {
#ifdef EXIF_DEBUG
exif_error_docref(NULL TSRMLS_CC, image_info, E_NOTICE,
"Adding %s as buffer%s", name, exif_char_dump(value, length, 0));
@@ -1809,10 +1743,6 @@
info_data->length = length;
} else {
info_data->value.s = emalloc(length+1);
- if (!info_data->value.s) {
- EXIF_ERRLOG_EALLOC
- return;
- }
memcpy(info_data->value.s, value, length);
info_data->value.s[length] = 0;
}
@@ -2308,10 +2238,6 @@
byte_count = php_tiff_bytes_per_format[info_data->format] * info_data->length;
value_ptr = emalloc(max(byte_count, 4));
- if (!value_ptr) {
- EXIF_ERRLOG_EALLOC
- return NULL;
- }
memset(value_ptr, 0, 4);
if (!info_data->length) {
return value_ptr;
@@ -2418,13 +2344,6 @@
}
new_move = new_size;
new_data = erealloc(ImageInfo->Thumbnail.data,
ImageInfo->Thumbnail.size+new_size);
- if (!new_data) {
- EXIF_ERRLOG_EALLOC
- efree(ImageInfo->Thumbnail.data);
- ImageInfo->Thumbnail.data = NULL;
- ImageInfo->Thumbnail.size = 0;
- return;
- }
ImageInfo->Thumbnail.data = new_data;
memmove(ImageInfo->Thumbnail.data + new_move,
ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size);
ImageInfo->Thumbnail.size += new_size;
@@ -2453,13 +2372,6 @@
php_ifd_set16u(new_data + 2,
info_data->format, ImageInfo->motorola_intel);
php_ifd_set32u(new_data + 4,
info_data->length, ImageInfo->motorola_intel);
value_ptr = exif_ifd_make_value(info_data,
ImageInfo->motorola_intel TSRMLS_CC);
- if (!value_ptr) {
- EXIF_ERRLOG_EALLOC
- efree(ImageInfo->Thumbnail.data);
- ImageInfo->Thumbnail.data = NULL;
- ImageInfo->Thumbnail.size = 0;
- return;
- }
if (byte_count <= 4) {
memmove(new_data+8, value_ptr, 4);
} else {
@@ -2507,9 +2419,6 @@
return;
}
ImageInfo->Thumbnail.data = estrndup(offset + ImageInfo->Thumbnail.offset,
ImageInfo->Thumbnail.size);
- if (!ImageInfo->Thumbnail.data) {
- EXIF_ERRLOG_EALLOC
- }
exif_thumbnail_build(ImageInfo TSRMLS_CC);
}
/* }}} */
@@ -2524,10 +2433,6 @@
*/
if (byte_count) {
(*result) = estrndup(value, byte_count); /* NULL @ byte_count!!! */
- if (!*result) {
- EXIF_ERRLOG_EALLOC
- return 0;
- }
return byte_count+1;
}
return 0;
@@ -2568,10 +2473,6 @@
return exif_process_undefined(result, value, byte_count TSRMLS_CC);
}
(*result) = estrndup("", 1); /* force empty string */
- if (!*result) {
- EXIF_ERRLOG_EALLOC
- return 0;
- }
return byte_count+1;
}
/* }}} */
@@ -2813,10 +2714,6 @@
if (byte_count>sizeof(cbuf)) {
/* mark as outside range and get buffer */
value_ptr = emalloc(byte_count);
- if (!value_ptr) {
- EXIF_ERRLOG_EALLOC
- return FALSE;
- }
outside = value_ptr;
} else {
/*
@@ -2903,11 +2800,8 @@
ImageInfo->CopyrightPhotographer =
estrdup(value_ptr);
ImageInfo->CopyrightEditor =
estrdup(value_ptr+length+1);
ImageInfo->Copyright =
emalloc(strlen(value_ptr)+strlen(value_ptr+length+1)+3);
- if (!ImageInfo->Copyright) {
- EXIF_ERRLOG_EALLOC
- } else {
- sprintf(ImageInfo->Copyright,
"%s, %s", value_ptr, value_ptr+length+1);
- }
+
+ sprintf(ImageInfo->Copyright, "%s,
+%s", value_ptr, value_ptr+length+1);
/* format = TAG_FMT_UNDEFINED; this
musn't be ASCII */
/* but we are not supposed to change
this */
/* keep in mind that image_info does
not store editor value */
@@ -2927,14 +2821,10 @@
case TAG_XP_KEYWORDS:
case TAG_XP_SUBJECT:
tmp_xp =
(xp_field_type*)erealloc(ImageInfo->xp_fields.list,
sizeof(xp_field_type)*(ImageInfo->xp_fields.count+1));
- if (!tmp_xp) {
- EXIF_ERRLOG_EALLOC
- } else {
- ImageInfo->sections_found |= FOUND_WINXP;
- ImageInfo->xp_fields.list = tmp_xp;
- ImageInfo->xp_fields.count++;
- exif_process_unicode(ImageInfo,
&(ImageInfo->xp_fields.list[ImageInfo->xp_fields.count-1]), tag, value_ptr, byte_count
TSRMLS_CC);
- }
+ ImageInfo->sections_found |= FOUND_WINXP;
+ ImageInfo->xp_fields.list = tmp_xp;
+ ImageInfo->xp_fields.count++;
+ exif_process_unicode(ImageInfo,
+&(ImageInfo->xp_fields.list[ImageInfo->xp_fields.count-1]), tag, value_ptr,
+byte_count TSRMLS_CC);
break;
case TAG_FNUMBER:
@@ -3267,10 +3157,7 @@
return FALSE;
}
- if ((sn=exif_file_sections_add(ImageInfo, marker, itemlen+1,
NULL))==-1) {
- EXIF_ERRLOG_EALLOC
- return FALSE;
- }
+ sn = exif_file_sections_add(ImageInfo, marker, itemlen+1, NULL);
Data = ImageInfo->file.list[sn].data;
/* Store first two pre-read bytes. */
@@ -3293,10 +3180,7 @@
/* Determine how much file is left. */
fpos = php_stream_tell(ImageInfo->infile);
size = ImageInfo->FileSize - fpos;
- if ((sn=exif_file_sections_add(ImageInfo,
M_PSEUDO, size, NULL))==-1) {
- EXIF_ERRLOG_EALLOC
- return FALSE;
- }
+ sn = exif_file_sections_add(ImageInfo,
+M_PSEUDO, size, NULL);
Data = ImageInfo->file.list[sn].data;
got = php_stream_read(ImageInfo->infile, Data,
size);
if (got != size) {
@@ -3461,10 +3345,7 @@
tag_table_type tag_table = exif_get_tag_table(section_index);
if (ImageInfo->FileSize >= dir_offset+2) {
- if ((sn=exif_file_sections_add(ImageInfo, M_PSEUDO, 2, NULL))==-1) {
- EXIF_ERRLOG_EALLOC
- return FALSE;
- }
+ sn = exif_file_sections_add(ImageInfo, M_PSEUDO, 2, NULL);
#ifdef EXIF_DEBUG
exif_error_docref(NULL TSRMLS_CC, ImageInfo, E_NOTICE, "read from
TIFF: filesize(x%04X), IFD dir(x%04X + x%04X)", ImageInfo->FileSize, dir_offset, 2);
#endif
@@ -3618,16 +3499,12 @@
#endif
if
(!ImageInfo->Thumbnail.data) {
ImageInfo->Thumbnail.data = emalloc(ImageInfo->Thumbnail.size);
- if
(!ImageInfo->Thumbnail.data) {
-
EXIF_ERRLOG_EALLOC
- } else {
-
php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET);
- fgot =
php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data,
ImageInfo->Thumbnail.size);
- if
(fgot < ImageInfo->Thumbnail.size) {
-
EXIF_ERRLOG_THUMBEOF
- }
-
exif_thumbnail_build(ImageInfo TSRMLS_CC);
+
+php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET);
+ fgot =
+php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data,
+ImageInfo->Thumbnail.size);
+ if (fgot <
+ImageInfo->Thumbnail.size) {
+
+EXIF_ERRLOG_THUMBEOF
}
+
+exif_thumbnail_build(ImageInfo TSRMLS_CC);
}
}
}
@@ -3655,16 +3532,12 @@
#endif
if (!ImageInfo->Thumbnail.data &&
ImageInfo->Thumbnail.offset && ImageInfo->Thumbnail.size && ImageInfo->read_thumbnail)
{
ImageInfo->Thumbnail.data =
emalloc(ImageInfo->Thumbnail.size);
- if (!ImageInfo->Thumbnail.data) {
- EXIF_ERRLOG_EALLOC
- } else {
-
php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET);
- fgot =
php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data,
ImageInfo->Thumbnail.size);
- if (fgot <
ImageInfo->Thumbnail.size) {
- EXIF_ERRLOG_THUMBEOF
- }
- exif_thumbnail_build(ImageInfo
TSRMLS_CC);
+ php_stream_seek(ImageInfo->infile,
+ImageInfo->Thumbnail.offset, SEEK_SET);
+ fgot =
+php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data,
+ImageInfo->Thumbnail.size);
+ if (fgot < ImageInfo->Thumbnail.size) {
+ EXIF_ERRLOG_THUMBEOF
}
+ exif_thumbnail_build(ImageInfo
+TSRMLS_CC);
}
#ifdef EXIF_DEBUG
exif_error_docref(NULL TSRMLS_CC, ImageInfo,
E_NOTICE, "read next IFD (THUMBNAIL) done");
@@ -3857,10 +3730,6 @@
if(ac >= 2) {
convert_to_string_ex(p_sections_needed);
sections_str = emalloc(strlen(Z_STRVAL_PP(p_sections_needed))+3);
- if (!sections_str) {
- EXIF_ERRLOG_EALLOC
- RETURN_FALSE;
- }
sprintf(sections_str, ",%s,", Z_STRVAL_PP(p_sections_needed));
/* sections_str DOES start with , and SPACES are NOT allowed in names
*/
s = sections_str;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php