Skip to content

Commit

Permalink
Small warning cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed Apr 5, 2021
1 parent 47fa50c commit 2c76d3b
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 87 deletions.
82 changes: 46 additions & 36 deletions src/lib/OpenEXRCore/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <limits.h>
#include <string.h>
#include <stdio.h>

/**************************************/

Expand Down Expand Up @@ -53,9 +52,9 @@ extract_chunk_table (
const struct _internal_exr_part* part,
uint64_t** chunktable)
{
uint64_t* ctable = NULL;

ctable = (uint64_t*) atomic_load (&(part->chunk_table));
uint64_t* ctable = NULL;
uintptr_t* ctableptr = (uintptr_t*) &(part->chunk_table);
ctable = (uint64_t*) atomic_load (ctableptr);
if (ctable == NULL)
{
uint64_t chunkoff = part->chunk_table_offset;
Expand Down Expand Up @@ -88,7 +87,7 @@ extract_chunk_table (
//EXR_GETFILE(f)->report_error( ctxt, EXR_ERR_UNKNOWN, "TODO: implement reconstructLineOffsets and similar" );
nptr = (uintptr_t) ctable;
// see if we win or not
if (!atomic_compare_exchange_strong (&(part->chunk_table), &eptr, nptr))
if (!atomic_compare_exchange_strong (ctableptr, &eptr, nptr))
{
ctxt->free_fn (ctable);
ctable = (uint64_t*) eptr;
Expand Down Expand Up @@ -274,7 +273,7 @@ exr_part_read_scanline_block_info (
return pctxt->print_error (
ctxt,
EXR_ERR_BAD_CHUNK_DATA,
"Request for deep scanline %d invalid sample table size %ld",
"Request for deep scanline %d invalid sample table size " PRId64,
y,
ddata[0]);
}
Expand All @@ -283,7 +282,8 @@ exr_part_read_scanline_block_info (
return pctxt->print_error (
ctxt,
EXR_ERR_BAD_CHUNK_DATA,
"Request for deep scanline %d large packed size %ld not supported",
"Request for deep scanline %d large packed size " PRId64
" not supported",
y,
ddata[1]);
}
Expand All @@ -292,7 +292,8 @@ exr_part_read_scanline_block_info (
return pctxt->print_error (
ctxt,
EXR_ERR_BAD_CHUNK_DATA,
"Request for deep scanline %d large unpacked size %ld not supported",
"Request for deep scanline %d large unpacked size " PRId64
" not supported",
y,
ddata[2]);
}
Expand Down Expand Up @@ -436,7 +437,7 @@ compute_tile_chunk_off (
return ctxt->print_error (
(const exr_context_t) ctxt,
EXR_ERR_UNKNOWN,
"Invalid tile chunk offset %ld (%d avail)",
"Invalid tile chunk offset " PRId64 " (%d avail)",
chunkoff,
part->chunk_count);
}
Expand Down Expand Up @@ -535,7 +536,8 @@ exr_part_read_tile_block_info (
return pctxt->print_error (
ctxt,
EXR_ERR_BAD_CHUNK_DATA,
"Request for tile (%d, %d), level (%d, %d) but unable to read %ld bytes from offset %ld, got %ld bytes",
"Request for tile (%d, %d), level (%d, %d) but unable to read " PRId64
" bytes from offset " PRId64 ", got " PRId64 " bytes",
tilex,
tiley,
levelx,
Expand Down Expand Up @@ -616,7 +618,7 @@ exr_part_read_tile_block_info (
return pctxt->print_error (
ctxt,
EXR_ERR_BAD_CHUNK_DATA,
"Request for deep tile (%d, %d), level (%d, %d) invalid sample table size %ld",
"Request for deep tile (%d, %d), level (%d, %d) invalid sample table size " PRId64,
tilex,
tiley,
levelx,
Expand All @@ -630,7 +632,7 @@ exr_part_read_tile_block_info (
return pctxt->print_error (
ctxt,
EXR_ERR_BAD_CHUNK_DATA,
"Request for deep tile (%d, %d), level (%d, %d) invalid packed size %ld",
"Request for deep tile (%d, %d), level (%d, %d) invalid packed size " PRId64,
tilex,
tiley,
levelx,
Expand All @@ -642,7 +644,7 @@ exr_part_read_tile_block_info (
return pctxt->print_error (
ctxt,
EXR_ERR_BAD_CHUNK_DATA,
"Request for deep tile (%d, %d), level (%d, %d) invalid unpacked size %ld",
"Request for deep tile (%d, %d), level (%d, %d) invalid unpacked size " PRId64,
tilex,
tiley,
levelx,
Expand All @@ -655,7 +657,8 @@ exr_part_read_tile_block_info (
return pctxt->print_error (
ctxt,
EXR_ERR_BAD_CHUNK_DATA,
"Request for deep tile (%d, %d), level (%d, %d) table (%ld) and/or data (%ld) size larger than file size %ld",
"Request for deep tile (%d, %d), level (%d, %d) table (" PRId64
") and/or data (" PRId64 ") size larger than file size " PRId64,
tilex,
tiley,
levelx,
Expand All @@ -679,7 +682,7 @@ exr_part_read_tile_block_info (
return pctxt->print_error (
ctxt,
EXR_ERR_BAD_CHUNK_DATA,
"Invalid data size found for tile (%d, %d) at level (%d, %d): %d unpack size %d file size %ld",
"Invalid data size found for tile (%d, %d) at level (%d, %d): %d unpack size %d file size " PRId64,
tilex,
tiley,
levelx,
Expand Down Expand Up @@ -737,7 +740,8 @@ exr_part_read_chunk (
return pctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"chunk block info data offset (%lu) past end of file (%ld)",
"chunk block info data offset (" PRIu64
") past end of file (" PRId64 ")",
dataoffset,
pctxt->file_size);

Expand Down Expand Up @@ -797,7 +801,8 @@ exr_part_read_deep_chunk (
return pctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"chunk block info sample count offset (%lu) past end of file (%ld)",
"chunk block info sample count offset (" PRIu64
") past end of file (" PRId64 ")",
cinfo->sample_count_data_offset,
pctxt->file_size);

Expand All @@ -806,7 +811,8 @@ exr_part_read_deep_chunk (
return pctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"chunk block info data offset (%lu) past end of file (%ld)",
"chunk block info data offset (" PRIu64
") past end of file (" PRId64 ")",
cinfo->data_offset,
pctxt->file_size);

Expand Down Expand Up @@ -877,28 +883,28 @@ write_scan_chunk (
return pctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"Invalid packed data argument size %lu pointer %p",
packed_size,
"Invalid packed data argument size " PRIu64 " pointer %p",
(uint64_t) packed_size,
packed_data);

if (part->storage_mode != EXR_STORAGE_DEEP_SCANLINE &&
packed_size > (size_t) INT32_MAX)
return pctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"Packed data size %lu too large (max %lu)",
packed_size,
(size_t) INT32_MAX);
"Packed data size " PRIu64 " too large (max " PRIu64 ")",
(uint64_t) packed_size,
(uint64_t) INT32_MAX);
psize = (int32_t) packed_size;

if (part->storage_mode == EXR_STORAGE_DEEP_SCANLINE &&
(!sample_data || sample_data_size == 0))
return pctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"Invalid sample count data argument size %lu pointer %p",
sample_data,
sample_data_size);
"Invalid sample count data argument size " PRIu64 " pointer %p",
(uint64_t) sample_data_size,
sample_data);

if (y < part->data_window.y_min || y > part->data_window.y_max)
{
Expand Down Expand Up @@ -1141,28 +1147,28 @@ write_tile_chunk (
return pctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"Invalid packed data argument size %lu pointer %p",
packed_size,
"Invalid packed data argument size " PRIu64 " pointer %p",
(uint64_t) packed_size,
packed_data);

if (part->storage_mode != EXR_STORAGE_DEEP_TILED &&
packed_size > (size_t) INT32_MAX)
return pctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"Packed data size %lu too large (max %lu)",
packed_size,
(size_t) INT32_MAX);
"Packed data size " PRIu64 " too large (max " PRIu64 ")",
(uint64_t) packed_size,
(uint64_t) INT32_MAX);
psize = (int32_t) packed_size;

if (part->storage_mode == EXR_STORAGE_DEEP_TILED &&
(!sample_data || sample_data_size == 0))
return pctxt->print_error (
ctxt,
EXR_ERR_INVALID_ARGUMENT,
"Invalid sample count data argument size %lu pointer %p",
sample_data,
sample_data_size);
"Invalid sample count data argument size " PRIu64 " pointer %p",
(uint64_t) sample_data_size,
sample_data);

if (!part->tiles || part->num_tile_levels_x <= 0 ||
part->num_tile_levels_y <= 0 || !part->tile_level_tile_count_x ||
Expand Down Expand Up @@ -1196,8 +1202,12 @@ write_tile_chunk (
if (part->lineorder != EXR_LINEORDER_RANDOM_Y &&
pctxt->last_output_chunk != (cidx - 1))
{
return pctxt->print_error (ctxt, EXR_ERR_CHUNK_NOT_READY,
"Chunk index %d is not the next chunk to be written (last %d)", cidx, pctxt->last_output_chunk);
return pctxt->print_error (
ctxt,
EXR_ERR_CHUNK_NOT_READY,
"Chunk index %d is not the next chunk to be written (last %d)",
cidx,
pctxt->last_output_chunk);
}

wrcnt = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/OpenEXRCore/decoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ alloc_buffer (
return pctxt->print_error (
(const exr_context_t) pctxt,
EXR_ERR_OUT_OF_MEMORY,
"Unable to allocate %lu bytes",
newsz);
"Unable to allocate " PRIu64 " bytes",
(uint64_t) newsz);
*buf = curbuf;
*cursz = newsz;
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/OpenEXRCore/internal_posix_file_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ default_read_func (
error_cb (
ctxt,
EXR_ERR_READ_IO,
"Unable to read %lu bytes: %s",
"Unable to read "PRIu64" bytes: %s",
sz,
strerror (errno));
return retsz;
Expand Down Expand Up @@ -312,7 +312,7 @@ default_write_func (
error_cb (
ctxt,
EXR_ERR_WRITE_IO,
"Unable to write %lu bytes to stream, wrote %ld: %s",
"Unable to write "PRIu64" bytes to stream, wrote "PRId64": %s",
sz,
retsz,
strerror (errno));
Expand Down Expand Up @@ -469,7 +469,7 @@ make_temp_filename (struct _internal_exr_context* ret)
return ret->print_error (
(const exr_context_t) ret,
EXR_ERR_OUT_OF_MEMORY,
"Unable to create %lu bytes for temporary filename",
(unsigned long) newlen + 1);
"Unable to create "PRIu64" bytes for temporary filename",
newlen + 1);
return EXR_ERR_SUCCESS;
}
14 changes: 12 additions & 2 deletions src/lib/OpenEXRCore/internal_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@
#ifdef ILMTHREAD_THREADING_ENABLED
# ifdef _WIN32
# include <windows.h>
# include <synchapi.h>
# else
# include <pthread.h>
# endif
#endif

#include <inttypes.h>

#ifdef _MSC_VER
# ifndef PRId64
# define PRId64 "I64d"
# endif
# ifndef PRIu64
# define PRIu64 "I64u"
# endif
#endif

/* for testing, we include a bunch of internal stuff into the unit tests which are in c++ */
#ifdef __cplusplus
# include <atomic>
Expand Down Expand Up @@ -175,10 +187,8 @@ struct _internal_exr_context
#ifdef ILMTHREAD_THREADING_ENABLED
# ifdef _WIN32
CRITICAL_SECTION mutex;
CRTIICAL_SECTION* need_unlock;
# else
pthread_mutex_t mutex;
pthread_mutex_t* need_unlock;
# endif
#endif
};
Expand Down
37 changes: 26 additions & 11 deletions src/lib/OpenEXRCore/internal_win32_file_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@

/* implementation for windows (win32) native file io routines (used in context.c) */

#include <windows.h>
#include <fileapi.h>
#include <inttypes.h>
#include <strsafe.h>
#include <windows.h>

#ifdef _MSC_VER
# ifndef PRId64
# define PRId64 "I64d"
# endif
# ifndef PRId64
# define PRIu64 "I64u"
# endif
#endif

static exr_result_t
print_error_helper (
Expand Down Expand Up @@ -40,19 +50,23 @@ print_error_helper (
if (FAILED (StringCchPrintf (
(LPTSTR) lpDisplayBuf,
bufsz,
TEXT ("%s: (%ld) %s"),
TEXT ("%s: (" PRId64 ") %s"),
msg,
dw,
(int64_t) dw,
lpMsgBuf)))
{
return pf->print_error (
(const exr_context_t)pf, EXR_ERR_OUT_OF_MEMORY, "Unable to format message print");
(const exr_context_t) pf,
EXR_ERR_OUT_OF_MEMORY,
"Unable to format message print");
}

if (error_cb)
error_cb ((const exr_context_t)pf, errcode, (const char*) lpDisplayBuf);
error_cb (
(const exr_context_t) pf, errcode, (const char*) lpDisplayBuf);
else
pf->print_error ((const exr_context_t)pf, errcode, (const char*) lpDisplayBuf);
pf->print_error (
(const exr_context_t) pf, errcode, (const char*) lpDisplayBuf);

LocalFree (lpMsgBuf);
LocalFree (lpDisplayBuf);
Expand Down Expand Up @@ -387,15 +401,16 @@ make_temp_filename (struct _internal_exr_context* ret)
_snprintf_s (tmproot, 32, _TRUNCATE, "tmp.%d", GetCurrentProcessId ());
if (nwr >= 32)
return ret->report_error (
(const exr_context_t)ret,
(const exr_context_t) ret,
EXR_ERR_INVALID_ARGUMENT,
"Invalid assumption in temporary filename");

tlen = strlen (tmproot);
newlen = tlen + (uint64_t) ret->filename.length;

if (newlen >= INT32_MAX)
return ret->standard_error ((const exr_context_t)ret, EXR_ERR_OUT_OF_MEMORY);
return ret->standard_error (
(const exr_context_t) ret, EXR_ERR_OUT_OF_MEMORY);

tmpname = ret->alloc_fn (newlen + 1);
if (tmpname)
Expand Down Expand Up @@ -440,9 +455,9 @@ make_temp_filename (struct _internal_exr_context* ret)
}
else
return ret->print_error (
(const exr_context_t)ret,
(const exr_context_t) ret,
EXR_ERR_OUT_OF_MEMORY,
"Unable to create %lu bytes for temporary filename",
(unsigned long) newlen + 1);
"Unable to create " PRIu64 " bytes for temporary filename",
(uint64_t) newlen + 1);
return EXR_ERR_SUCCESS;
}
Loading

0 comments on commit 2c76d3b

Please sign in to comment.