Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/imbuf/intern/jpeg.c')
-rw-r--r--source/blender/imbuf/intern/jpeg.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c
index 525284bd867..93cdbbb1407 100644
--- a/source/blender/imbuf/intern/jpeg.c
+++ b/source/blender/imbuf/intern/jpeg.c
@@ -57,12 +57,13 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int fla
static const uchar jpeg_default_quality = 75;
static uchar ibuf_quality;
-int imb_is_a_jpeg(const unsigned char *mem)
+bool imb_is_a_jpeg(const unsigned char *mem, const size_t size)
{
- if ((mem[0] == 0xFF) && (mem[1] == 0xD8)) {
- return 1;
+ const char magic[2] = {0xFF, 0xD8};
+ if (size < sizeof(magic)) {
+ return false;
}
- return 0;
+ return memcmp(mem, magic, sizeof(magic)) == 0;
}
/*----------------------------------------------------------
@@ -246,7 +247,7 @@ static boolean handle_app1(j_decompress_ptr cinfo)
INPUT_BYTE(cinfo, neogeo[i], return false);
}
length = 0;
- if (STREQLEN(neogeo, "NeoGeo", 6)) {
+ if (STRPREFIX(neogeo, "NeoGeo")) {
struct NeoGeo_Word *neogeo_word = (struct NeoGeo_Word *)(neogeo + 6);
ibuf_quality = neogeo_word->quality;
}
@@ -362,7 +363,7 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int fla
* That is why we need split it to the
* common key/value here.
*/
- if (!STREQLEN(str, "Blender", 7)) {
+ if (!STRPREFIX(str, "Blender")) {
/*
* Maybe the file have text that
* we don't know "what it's", in that
@@ -429,7 +430,7 @@ ImBuf *imb_load_jpeg(const unsigned char *buffer,
struct my_error_mgr jerr;
ImBuf *ibuf;
- if (!imb_is_a_jpeg(buffer)) {
+ if (!imb_is_a_jpeg(buffer, size)) {
return NULL;
}
@@ -608,7 +609,7 @@ static int init_jpeg(FILE *outfile, struct jpeg_compress_struct *cinfo, struct I
return 0;
}
-static int save_stdjpeg(const char *name, struct ImBuf *ibuf)
+static bool save_stdjpeg(const char *name, struct ImBuf *ibuf)
{
FILE *outfile;
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
@@ -642,7 +643,7 @@ static int save_stdjpeg(const char *name, struct ImBuf *ibuf)
return 1;
}
-int imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags)
+bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags)
{
ibuf->flags = flags;