diff options
| author | Paul Eggert | 2011-06-05 23:10:06 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-05 23:10:06 -0700 |
| commit | dd52fcea063f37a9875bf9196dbe11a442e8adfc (patch) | |
| tree | 63f3c4a06456cdc3f025a0b4b4089f7be42108ec /src | |
| parent | 7f9bbdbbd60a3c9052537cd4b65a3a6d959b7746 (diff) | |
| download | emacs-dd52fcea063f37a9875bf9196dbe11a442e8adfc.tar.gz emacs-dd52fcea063f37a9875bf9196dbe11a442e8adfc.zip | |
* image.c: Use ptrdiff_t, not int, for sizes.
(slurp_file): Switch from int to ptrdiff_t.
All uses changed.
(slurp_file): Check that file size fits in both size_t (for
malloc) and ptrdiff_t (for sanity and safety).
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/image.c | 19 |
2 files changed, 15 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index f86b0decf3c..7fb1479e548 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2011-06-06 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-06-06 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * image.c: Use ptrdiff_t, not int, for sizes. | ||
| 4 | (slurp_file): Switch from int to ptrdiff_t. | ||
| 5 | All uses changed. | ||
| 6 | (slurp_file): Check that file size fits in both size_t (for | ||
| 7 | malloc) and ptrdiff_t (for sanity and safety). | ||
| 8 | |||
| 3 | * fileio.c (Fverify_visited_file_modtime): Avoid time overflow | 9 | * fileio.c (Fverify_visited_file_modtime): Avoid time overflow |
| 4 | if b->modtime has its maximal value. | 10 | if b->modtime has its maximal value. |
| 5 | 11 | ||
diff --git a/src/image.c b/src/image.c index 26542bf27e7..a179568cb85 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -2112,9 +2112,6 @@ x_put_x_image (struct frame *f, XImagePtr ximg, Pixmap pixmap, int width, int he | |||
| 2112 | File Handling | 2112 | File Handling |
| 2113 | ***********************************************************************/ | 2113 | ***********************************************************************/ |
| 2114 | 2114 | ||
| 2115 | static unsigned char *slurp_file (char *, int *); | ||
| 2116 | |||
| 2117 | |||
| 2118 | /* Find image file FILE. Look in data-directory/images, then | 2115 | /* Find image file FILE. Look in data-directory/images, then |
| 2119 | x-bitmap-file-path. Value is the encoded full name of the file | 2116 | x-bitmap-file-path. Value is the encoded full name of the file |
| 2120 | found, or nil if not found. */ | 2117 | found, or nil if not found. */ |
| @@ -2151,7 +2148,7 @@ x_find_image_file (Lisp_Object file) | |||
| 2151 | occurred. *SIZE is set to the size of the file. */ | 2148 | occurred. *SIZE is set to the size of the file. */ |
| 2152 | 2149 | ||
| 2153 | static unsigned char * | 2150 | static unsigned char * |
| 2154 | slurp_file (char *file, int *size) | 2151 | slurp_file (char *file, ptrdiff_t *size) |
| 2155 | { | 2152 | { |
| 2156 | FILE *fp = NULL; | 2153 | FILE *fp = NULL; |
| 2157 | unsigned char *buf = NULL; | 2154 | unsigned char *buf = NULL; |
| @@ -2159,6 +2156,7 @@ slurp_file (char *file, int *size) | |||
| 2159 | 2156 | ||
| 2160 | if (stat (file, &st) == 0 | 2157 | if (stat (file, &st) == 0 |
| 2161 | && (fp = fopen (file, "rb")) != NULL | 2158 | && (fp = fopen (file, "rb")) != NULL |
| 2159 | && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX) | ||
| 2162 | && (buf = (unsigned char *) xmalloc (st.st_size), | 2160 | && (buf = (unsigned char *) xmalloc (st.st_size), |
| 2163 | fread (buf, 1, st.st_size, fp) == st.st_size)) | 2161 | fread (buf, 1, st.st_size, fp) == st.st_size)) |
| 2164 | { | 2162 | { |
| @@ -2814,7 +2812,7 @@ xbm_load (struct frame *f, struct image *img) | |||
| 2814 | { | 2812 | { |
| 2815 | Lisp_Object file; | 2813 | Lisp_Object file; |
| 2816 | unsigned char *contents; | 2814 | unsigned char *contents; |
| 2817 | int size; | 2815 | ptrdiff_t size; |
| 2818 | 2816 | ||
| 2819 | file = x_find_image_file (file_name); | 2817 | file = x_find_image_file (file_name); |
| 2820 | if (!STRINGP (file)) | 2818 | if (!STRINGP (file)) |
| @@ -4039,7 +4037,7 @@ xpm_load (struct frame *f, | |||
| 4039 | { | 4037 | { |
| 4040 | Lisp_Object file; | 4038 | Lisp_Object file; |
| 4041 | unsigned char *contents; | 4039 | unsigned char *contents; |
| 4042 | int size; | 4040 | ptrdiff_t size; |
| 4043 | 4041 | ||
| 4044 | file = x_find_image_file (file_name); | 4042 | file = x_find_image_file (file_name); |
| 4045 | if (!STRINGP (file)) | 4043 | if (!STRINGP (file)) |
| @@ -5021,6 +5019,7 @@ pbm_read_file (file, size) | |||
| 5021 | 5019 | ||
| 5022 | if (stat (SDATA (file), &st) == 0 | 5020 | if (stat (SDATA (file), &st) == 0 |
| 5023 | && (fp = fopen (SDATA (file), "rb")) != NULL | 5021 | && (fp = fopen (SDATA (file), "rb")) != NULL |
| 5022 | && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX) | ||
| 5024 | && (buf = (char *) xmalloc (st.st_size), | 5023 | && (buf = (char *) xmalloc (st.st_size), |
| 5025 | fread (buf, 1, st.st_size, fp) == st.st_size)) | 5024 | fread (buf, 1, st.st_size, fp) == st.st_size)) |
| 5026 | { | 5025 | { |
| @@ -5055,7 +5054,7 @@ pbm_load (struct frame *f, struct image *img) | |||
| 5055 | enum {PBM_MONO, PBM_GRAY, PBM_COLOR} type; | 5054 | enum {PBM_MONO, PBM_GRAY, PBM_COLOR} type; |
| 5056 | unsigned char *contents = NULL; | 5055 | unsigned char *contents = NULL; |
| 5057 | unsigned char *end, *p; | 5056 | unsigned char *end, *p; |
| 5058 | int size; | 5057 | ptrdiff_t size; |
| 5059 | 5058 | ||
| 5060 | specified_file = image_spec_value (img->spec, QCfile, NULL); | 5059 | specified_file = image_spec_value (img->spec, QCfile, NULL); |
| 5061 | 5060 | ||
| @@ -7869,7 +7868,7 @@ static int svg_image_p (Lisp_Object object); | |||
| 7869 | static int svg_load (struct frame *f, struct image *img); | 7868 | static int svg_load (struct frame *f, struct image *img); |
| 7870 | 7869 | ||
| 7871 | static int svg_load_image (struct frame *, struct image *, | 7870 | static int svg_load_image (struct frame *, struct image *, |
| 7872 | unsigned char *, unsigned int); | 7871 | unsigned char *, ptrdiff_t); |
| 7873 | 7872 | ||
| 7874 | /* The symbol `svg' identifying images of this type. */ | 7873 | /* The symbol `svg' identifying images of this type. */ |
| 7875 | 7874 | ||
| @@ -8047,7 +8046,7 @@ svg_load (struct frame *f, struct image *img) | |||
| 8047 | { | 8046 | { |
| 8048 | Lisp_Object file; | 8047 | Lisp_Object file; |
| 8049 | unsigned char *contents; | 8048 | unsigned char *contents; |
| 8050 | int size; | 8049 | ptrdiff_t size; |
| 8051 | 8050 | ||
| 8052 | file = x_find_image_file (file_name); | 8051 | file = x_find_image_file (file_name); |
| 8053 | if (!STRINGP (file)) | 8052 | if (!STRINGP (file)) |
| @@ -8096,7 +8095,7 @@ static int | |||
| 8096 | svg_load_image (struct frame *f, /* Pointer to emacs frame structure. */ | 8095 | svg_load_image (struct frame *f, /* Pointer to emacs frame structure. */ |
| 8097 | struct image *img, /* Pointer to emacs image structure. */ | 8096 | struct image *img, /* Pointer to emacs image structure. */ |
| 8098 | unsigned char *contents, /* String containing the SVG XML data to be parsed. */ | 8097 | unsigned char *contents, /* String containing the SVG XML data to be parsed. */ |
| 8099 | unsigned int size) /* Size of data in bytes. */ | 8098 | ptrdiff_t size) /* Size of data in bytes. */ |
| 8100 | { | 8099 | { |
| 8101 | RsvgHandle *rsvg_handle; | 8100 | RsvgHandle *rsvg_handle; |
| 8102 | RsvgDimensionData dimension_data; | 8101 | RsvgDimensionData dimension_data; |