Skip to content

Commit 64569d3

Browse files
committed
ext/exif: Add some const qualifiers
1 parent 96d41a6 commit 64569d3

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

ext/exif/exif.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ typedef struct {
18331833
#define FOUND_WINXP (1<<SECTION_WINXP)
18341834
#define FOUND_MAKERNOTE (1<<SECTION_MAKERNOTE)
18351835

1836-
static char *exif_get_sectionname(int section)
1836+
static const char *exif_get_sectionname(int section)
18371837
{
18381838
switch(section) {
18391839
case SECTION_FILE: return "FILE";
@@ -2047,7 +2047,7 @@ typedef struct {
20472047
char *valid_end; /* exclusive */
20482048
} exif_offset_info;
20492049

2050-
static zend_always_inline bool ptr_offset_overflows(char *ptr, size_t offset) {
2050+
static zend_always_inline bool ptr_offset_overflows(const char *ptr, size_t offset) {
20512051
return UINTPTR_MAX - (uintptr_t) ptr < offset;
20522052
}
20532053

@@ -2084,15 +2084,14 @@ static inline char *exif_offset_info_try_get(
20842084
}
20852085

20862086
static inline bool exif_offset_info_contains(
2087-
const exif_offset_info *info, char *start, size_t length) {
2088-
char *end;
2087+
const exif_offset_info *info, const char *start, size_t length) {
20892088
if (ptr_offset_overflows(start, length)) {
20902089
return 0;
20912090
}
20922091

20932092
/* start and valid_start are both inclusive, end and valid_end are both exclusive,
20942093
* so we use >= and <= to do the checks, respectively. */
2095-
end = start + length;
2094+
const char *end = start + length;
20962095
return start >= info->valid_start && end <= info->valid_end;
20972096
}
20982097

@@ -2184,7 +2183,7 @@ static image_info_data *exif_alloc_image_info_data(image_info_list *info_list) {
21842183
/* {{{ exif_iif_add_value
21852184
Add a value to image_info
21862185
*/
2187-
static void exif_iif_add_value(image_info_type *image_info, int section_index, char *name, int tag, int format, size_t length, void* value, size_t value_len, int motorola_intel)
2186+
static void exif_iif_add_value(image_info_type *image_info, int section_index, const char *name, int tag, int format, size_t length, void* value, size_t value_len, int motorola_intel)
21882187
{
21892188
size_t idex;
21902189
void *vptr, *vptr_end;
@@ -2323,7 +2322,7 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
23232322
/* {{{ exif_iif_add_tag
23242323
Add a tag from IFD to image_info
23252324
*/
2326-
static void exif_iif_add_tag(image_info_type *image_info, int section_index, char *name, int tag, int format, size_t length, void* value, size_t value_len)
2325+
static void exif_iif_add_tag(image_info_type *image_info, int section_index, const char *name, int tag, int format, size_t length, void* value, size_t value_len)
23272326
{
23282327
exif_iif_add_value(image_info, section_index, name, tag, format, length, value, value_len, image_info->motorola_intel);
23292328
}
@@ -2332,7 +2331,7 @@ static void exif_iif_add_tag(image_info_type *image_info, int section_index, cha
23322331
/* {{{ exif_iif_add_int
23332332
Add an int value to image_info
23342333
*/
2335-
static void exif_iif_add_int(image_info_type *image_info, int section_index, char *name, int value)
2334+
static void exif_iif_add_int(image_info_type *image_info, int section_index, const char *name, int value)
23362335
{
23372336
image_info_data *info_data = exif_alloc_image_info_data(&image_info->info_list[section_index]);
23382337
info_data->tag = TAG_NONE;
@@ -2347,7 +2346,7 @@ static void exif_iif_add_int(image_info_type *image_info, int section_index, cha
23472346
/* {{{ exif_iif_add_str
23482347
Add a string value to image_info MUST BE NUL TERMINATED
23492348
*/
2350-
static void exif_iif_add_str(image_info_type *image_info, int section_index, char *name, char *value)
2349+
static void exif_iif_add_str(image_info_type *image_info, int section_index, const char *name, const char *value)
23512350
{
23522351
if (value) {
23532352
image_info_data *info_data =
@@ -2365,7 +2364,7 @@ static void exif_iif_add_str(image_info_type *image_info, int section_index, cha
23652364
/* {{{ exif_iif_add_fmt
23662365
Add a format string value to image_info MUST BE NUL TERMINATED
23672366
*/
2368-
static void exif_iif_add_fmt(image_info_type *image_info, int section_index, char *name, char *value, ...)
2367+
static void exif_iif_add_fmt(image_info_type *image_info, int section_index, const char *name, char *value, ...)
23692368
{
23702369
char *tmp;
23712370
va_list arglist;
@@ -2383,7 +2382,7 @@ static void exif_iif_add_fmt(image_info_type *image_info, int section_index, cha
23832382
/* {{{ exif_iif_add_str
23842383
Add a string value to image_info MUST BE NUL TERMINATED
23852384
*/
2386-
static void exif_iif_add_buffer(image_info_type *image_info, int section_index, char *name, int length, char *value)
2385+
static void exif_iif_add_buffer(image_info_type *image_info, int section_index, const char *name, int length, const char *value)
23872386
{
23882387
if (value) {
23892388
image_info_data *info_data =
@@ -2979,7 +2978,7 @@ static void exif_thumbnail_extract(image_info_type *ImageInfo, const exif_offset
29792978

29802979
/* {{{ exif_process_undefined
29812980
* Copy a string/buffer in Exif header to a character string and return length of allocated buffer if any. */
2982-
static int exif_process_undefined(char **result, char *value, size_t byte_count) {
2981+
static int exif_process_undefined(char **result, const char *value, size_t byte_count) {
29832982
/* we cannot use strlcpy - here the problem is that we have to copy NUL
29842983
* chars up to byte_count, we also have to add a single NUL character to
29852984
* force end of string.
@@ -2995,7 +2994,7 @@ static int exif_process_undefined(char **result, char *value, size_t byte_count)
29952994

29962995
/* {{{ exif_process_string_raw
29972996
* Copy a string in Exif header to a character string returns length of allocated buffer if any. */
2998-
static int exif_process_string_raw(char **result, char *value, size_t byte_count) {
2997+
static int exif_process_string_raw(char **result, const char *value, size_t byte_count) {
29992998
/* we cannot use strlcpy - here the problem is that we have to copy NUL
30002999
* chars up to byte_count, we also have to add a single NUL character to
30013000
* force end of string.
@@ -3013,7 +3012,7 @@ static int exif_process_string_raw(char **result, char *value, size_t byte_count
30133012
/* {{{ exif_process_string
30143013
* Copy a string in Exif header to a character string and return length of allocated buffer if any.
30153014
* In contrast to exif_process_string this function does always return a string buffer */
3016-
static int exif_process_string(char **result, char *value, size_t byte_count) {
3015+
static int exif_process_string(char **result, const char *value, size_t byte_count) {
30173016
/* we cannot use strlcpy - here the problem is that we cannot use strlen to
30183017
* determine length of string and we cannot use strlcpy with len=byte_count+1
30193018
* because then we might get into an EXCEPTION if we exceed an allocated
@@ -3031,7 +3030,7 @@ static int exif_process_string(char **result, char *value, size_t byte_count) {
30313030

30323031
/* {{{ exif_process_user_comment
30333032
* Process UserComment in IFD. */
3034-
static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount)
3033+
static int exif_process_user_comment(const image_info_type *ImageInfo, char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount)
30353034
{
30363035
int a;
30373036
char *decode;
@@ -3119,15 +3118,15 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
31193118

31203119
/* {{{ exif_process_unicode
31213120
* Process unicode field in IFD. */
3122-
static int exif_process_unicode(image_info_type *ImageInfo, xp_field_type *xp_field, int tag, char *szValuePtr, int ByteCount)
3121+
static int exif_process_unicode(const image_info_type *ImageInfo, xp_field_type *xp_field, int tag, const char *szValuePtr, int ByteCount)
31233122
{
31243123
xp_field->tag = tag;
31253124
xp_field->value = NULL;
31263125
/* XXX this will fail again if encoding_converter returns on error something different than SIZE_MAX */
31273126
if (zend_multibyte_encoding_converter(
31283127
(unsigned char**)&xp_field->value,
31293128
&xp_field->size,
3130-
(unsigned char*)szValuePtr,
3129+
(const unsigned char*)szValuePtr,
31313130
ByteCount,
31323131
zend_multibyte_fetch_encoding(ImageInfo->encode_unicode),
31333132
zend_multibyte_fetch_encoding(ImageInfo->motorola_intel ? ImageInfo->decode_unicode_be : ImageInfo->decode_unicode_le)
@@ -4463,7 +4462,7 @@ static bool exif_read_from_stream(image_info_type *ImageInfo, php_stream *stream
44634462
/* }}} */
44644463

44654464
/* {{{ exif_read_from_file */
4466-
static bool exif_read_from_file(image_info_type *ImageInfo, char *FileName, int read_thumbnail, int read_all)
4465+
static bool exif_read_from_file(image_info_type *ImageInfo, const char *FileName, int read_thumbnail, int read_all)
44674466
{
44684467
bool ret;
44694468
php_stream *stream;

0 commit comments

Comments
 (0)