Skip to content

Commit 5aee86f

Browse files
committed
Avoid Sonar warnings about unsafe use of strlen
Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 02a852e commit 5aee86f

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/jpeg.imageio/jpegoutput.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ JpgOutput::open(const std::string& name, const ImageSpec& newspec,
290290
std::vector<char> iptc;
291291
if (m_spec.get_int_attribute("jpeg:iptc", 1)
292292
&& encode_iptc_iim(m_spec, iptc)) {
293-
static char photoshop[] = "Photoshop 3.0";
293+
static const char* photoshop = "Photoshop 3.0";
294294
std::vector<char> head(photoshop, photoshop + strlen(photoshop) + 1);
295-
static char _8BIM[] = "8BIM";
295+
static const char* _8BIM = "8BIM";
296296
head.insert(head.end(), _8BIM, _8BIM + 4);
297297
head.push_back(4); // 0x0404
298298
head.push_back(4);
@@ -310,7 +310,7 @@ JpgOutput::open(const std::string& name, const ImageSpec& newspec,
310310
// Write XMP packet, if we have anything
311311
std::string xmp = encode_xmp(m_spec, true);
312312
if (!xmp.empty()) {
313-
static char prefix[] = "http://ns.adobe.com/xap/1.0/"; //NOSONAR
313+
static const char* prefix = "http://ns.adobe.com/xap/1.0/";
314314
std::vector<char> block(prefix, prefix + strlen(prefix) + 1);
315315
block.insert(block.end(), xmp.c_str(), xmp.c_str() + xmp.length());
316316
jpeg_write_marker(&m_cinfo, JPEG_APP0 + 1, (JOCTET*)&block[0],

src/libOpenImageIO/exif.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,10 @@ add_exif_item_to_spec(ImageSpec& spec, const char* name,
737737
while (dspan.size() && dspan.back() == 0)
738738
dspan = dspan.subspan(0, dspan.size() - 1);
739739
std::string str(dspan.begin(), dspan.end());
740-
if (strlen(str.c_str()) < str.length()) // Stray \0 in the middle
740+
if (Strutil::safe_strlen(str.c_str(), str.length()) < str.length()) {
741+
// Stray \0 in the middle
741742
str = std::string(str.c_str());
743+
}
742744
spec.attribute(name, str);
743745
return;
744746
}

0 commit comments

Comments
 (0)