Skip to content

Commit aeeb3e7

Browse files
authored
oiiotool internals: convert all error and warning to fmt style (#3240)
Also tagged Strutil and ustring::fmtformat as 'nodiscard', to produce warnings if people call it and ignore the results. (As was the case in my own bug that I tracked down in the course of this patch.)
1 parent fe9d572 commit aeeb3e7

File tree

6 files changed

+130
-129
lines changed

6 files changed

+130
-129
lines changed

src/include/OpenImageIO/strutil.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ using ::fmt::sprintf;
137137

138138
namespace fmt {
139139
template<typename Str, typename... Args>
140+
OIIO_NODISCARD
140141
inline std::string format(const Str& fmt, Args&&... args)
141142
{
142143
#if FMT_VERSION >= 70000

src/include/OpenImageIO/ustring.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ class OIIO_UTIL_API ustring {
639639
/// The formatting of the string will always use the classic "C" locale
640640
/// conventions (in particular, '.' as decimal separator for float values).
641641
template<typename... Args>
642-
static ustring sprintf(const char* fmt, const Args&... args)
642+
OIIO_NODISCARD static ustring sprintf(const char* fmt, const Args&... args)
643643
{
644644
return ustring(Strutil::sprintf(fmt, args...));
645645
}
@@ -651,7 +651,8 @@ class OIIO_UTIL_API ustring {
651651
/// The formatting of the string will always use the classic "C" locale
652652
/// conventions (in particular, '.' as decimal separator for float values).
653653
template<typename... Args>
654-
static ustring fmtformat(const char* fmt, const Args&... args)
654+
OIIO_NODISCARD static ustring fmtformat(const char* fmt,
655+
const Args&... args)
655656
{
656657
return ustring(Strutil::fmt::format(fmt, args...));
657658
}

src/oiiotool/imagerec.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ ImageRec::read_nativespec()
206206
ustring uname(name());
207207
if (!m_imagecache->get_image_info(uname, 0, 0, u_subimages, TypeInt,
208208
&subimages)) {
209-
errorf("file not found: \"%s\"", name());
209+
errorfmt("file not found: \"{}\"", name());
210210
return false; // Image not found
211211
}
212212
m_subimages.resize(subimages);
@@ -223,7 +223,7 @@ ImageRec::read_nativespec()
223223
new ImageBuf(name(), s, m, m_imagecache, m_configspec.get()));
224224
bool ok = ib->init_spec(name(), s, m);
225225
if (!ok)
226-
errorf("%s", ib->geterror());
226+
errorfmt("{}", ib->geterror());
227227
allok &= ok;
228228
m_subimages[s].m_miplevels[m] = ib;
229229
m_subimages[s].m_specs[m] = ib->spec();
@@ -245,7 +245,7 @@ ImageRec::read(ReadPolicy readpolicy, string_view channel_set)
245245
ustring uname(name());
246246
if (!m_imagecache->get_image_info(uname, 0, 0, u_subimages, TypeInt,
247247
&subimages)) {
248-
errorf("file not found: \"%s\"", name());
248+
errorfmt("file not found: \"{}\"", name());
249249
return false; // Image not found
250250
}
251251
m_subimages.resize(subimages);
@@ -335,7 +335,7 @@ ImageRec::read(ReadPolicy readpolicy, string_view channel_set)
335335
&newchannelnames[0], false);
336336
}
337337
if (!ok)
338-
errorf("%s", ib->geterror());
338+
errorfmt("{}", ib->geterror());
339339

340340
allok &= ok;
341341
// Remove any existing SHA-1 hash from the spec.

0 commit comments

Comments
 (0)