Skip to content

Commit

Permalink
clang-tidy: avoid global non const variables
Browse files Browse the repository at this point in the history
Found with cppcoreguidelines-avoid-non-const-global-variables

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed May 20, 2021
1 parent 8dbc699 commit 43a91a4
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 132 deletions.
2 changes: 1 addition & 1 deletion include/exiv2/datasets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespace Exiv2 {
static int dataSetIdx(uint16_t number, uint16_t recordId);
static int dataSetIdx(const std::string& dataSetName, uint16_t recordId);

static const DataSet* records_[];
static const DataSet* const records_[];
static const RecordInfo recordInfo_[];

}; // class IptcDataSets
Expand Down
16 changes: 9 additions & 7 deletions include/exiv2/jpgimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// *****************************************************************************
#include "exiv2lib_export.h"

#include <array>

// included header files
#include "image.hpp"

Expand All @@ -46,9 +48,9 @@ namespace Exiv2 {
*/
struct EXIV2API Photoshop {
// Todo: Public for now
static const char ps3Id_[]; //!< %Photoshop marker
static const char* irbId_[]; //!< %Photoshop IRB markers
static const char bimId_[]; //!< %Photoshop IRB marker (deprecated)
static const char* const ps3Id_; //!< %Photoshop marker
static const std::array<const char*, 4> irbId_; //!< %Photoshop IRB markers
static const char* const bimId_; //!< %Photoshop IRB marker (deprecated)
static const uint16_t iptc_; //!< %Photoshop IPTC marker
static const uint16_t preview_; //!< %Photoshop preview marker

Expand Down Expand Up @@ -232,10 +234,10 @@ namespace Exiv2 {
static const byte sof13_; //!< JPEG Start-Of-Frame marker
static const byte sof14_; //!< JPEG Start-Of-Frame marker
static const byte sof15_; //!< JPEG Start-Of-Frame marker
static const char exifId_[]; //!< Exif identifier
static const char jfifId_[]; //!< JFIF identifier
static const char xmpId_[]; //!< XMP packet identifier
static const char iccId_[]; //!< ICC profile identifier
static const char* const exifId_; //!< Exif identifier
static const char* const jfifId_; //!< JFIF identifier
static const char* const xmpId_; //!< XMP packet identifier
static const char* const iccId_; //!< ICC profile identifier

private:
//! @name NOT implemented
Expand Down
29 changes: 14 additions & 15 deletions include/exiv2/webpimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,20 @@ namespace Exiv2 {
//@}

private:
const static byte WEBP_PAD_ODD;
const static int WEBP_TAG_SIZE;
const static int WEBP_VP8X_ICC_BIT;
const static int WEBP_VP8X_ALPHA_BIT;
const static int WEBP_VP8X_EXIF_BIT;
const static int WEBP_VP8X_XMP_BIT;
const static char* WEBP_CHUNK_HEADER_VP8X;
const static char* WEBP_CHUNK_HEADER_VP8L;
const static char* WEBP_CHUNK_HEADER_VP8;
const static char* WEBP_CHUNK_HEADER_ANMF;
const static char* WEBP_CHUNK_HEADER_ANIM;
const static char* WEBP_CHUNK_HEADER_ICCP;
const static char* WEBP_CHUNK_HEADER_EXIF;
const static char* WEBP_CHUNK_HEADER_XMP;

static const byte WEBP_PAD_ODD;
static const int WEBP_TAG_SIZE;
static const int WEBP_VP8X_ICC_BIT;
static const int WEBP_VP8X_ALPHA_BIT;
static const int WEBP_VP8X_EXIF_BIT;
static const int WEBP_VP8X_XMP_BIT;
static const char* const WEBP_CHUNK_HEADER_VP8X;
static const char* const WEBP_CHUNK_HEADER_VP8L;
static const char* const WEBP_CHUNK_HEADER_VP8;
static const char* const WEBP_CHUNK_HEADER_ANMF;
static const char* const WEBP_CHUNK_HEADER_ANIM;
static const char* const WEBP_CHUNK_HEADER_ICCP;
static const char* const WEBP_CHUNK_HEADER_EXIF;
static const char* const WEBP_CHUNK_HEADER_XMP;

}; //Class WebPImage

Expand Down
3 changes: 0 additions & 3 deletions src/cr2header_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Exiv2 {
namespace Internal {

const char* Cr2Header::cr2sig_ = "CR\2\0";

Cr2Header::Cr2Header(ByteOrder byteOrder)
: TiffHeaderBase(42, 16, byteOrder, 0x00000010),
offset2_(0x00000000)
Expand Down
2 changes: 1 addition & 1 deletion src/cr2header_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace Exiv2 {
private:
// DATA
uint32_t offset2_; //!< Bytes 12-15 from the header
static const char* cr2sig_; //!< Signature for CR2 type TIFF
static constexpr auto cr2sig_ = "CR\2\0"; //!< Signature for CR2 type TIFF
}; // class Cr2Header

}} // namespace Internal, Exiv2
Expand Down
15 changes: 8 additions & 7 deletions src/datasets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace Exiv2 {
{IptcDataSets::application2, "Application2", N_("IIM application record 2")},
};

static const DataSet envelopeRecord[] = {
constexpr DataSet envelopeRecord[] = {
{IptcDataSets::ModelVersion, "ModelVersion", N_("Model Version"),
N_("A binary number identifying the version of the Information "
"Interchange Model, Part I, utilised by the provider. Version "
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace Exiv2 {
return envelopeRecord;
}

static const DataSet application2Record[] = {
constexpr DataSet application2Record[] = {
{IptcDataSets::RecordVersion, "RecordVersion", N_("Record Version"),
N_("A binary number identifying the version of the Information "
"Interchange Model, Part II, utilised by the provider. "
Expand Down Expand Up @@ -407,18 +407,19 @@ namespace Exiv2 {
return application2Record;
}

static const DataSet unknownDataSet{0xffff, "Unknown dataset", N_("Unknown dataset"),
constexpr DataSet unknownDataSet{0xffff, "Unknown dataset", N_("Unknown dataset"),
N_("Unknown dataset"),
false, true, 0, 0xffffffff, Exiv2::string,
IptcDataSets::invalidRecord,
N_("Unknown dataset")};
N_("Unknown dataset"),};

// Dataset lookup lists.This is an array with pointers to one list per IIM4 Record.
// The record id is used as the index into the array.
const DataSet* IptcDataSets::records_[] = {
constexpr const DataSet* IptcDataSets::records_[] = {
0,
envelopeRecord,
application2Record,
0,
envelopeRecord, application2Record,
0
};

int IptcDataSets::dataSetIdx(uint16_t number, uint16_t recordId)
Expand Down
30 changes: 17 additions & 13 deletions src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// + standard includes
#include <sys/types.h>
#include <sys/stat.h>
#include <array>
#include <cstdio>
#include <cerrno>
#include <sstream>
Expand Down Expand Up @@ -67,10 +68,17 @@
#endif

namespace Exiv2 {
const char* ENVARDEF[] = {"/exiv2.php", "40"}; //!< @brief default URL for http exiv2 handler and time-out
const char* ENVARKEY[] = {"EXIV2_HTTP_POST", "EXIV2_TIMEOUT"}; //!< @brief request keys for http exiv2 handler and time-out
// *****************************************************************************
// free functions
constexpr std::array<const char*, 2> ENVARDEF{
"/exiv2.php",
"40",
}; //!< @brief default URL for http exiv2 handler and time-out
constexpr std::array<const char*, 2> ENVARKEY{
"EXIV2_HTTP_POST",
"EXIV2_TIMEOUT",
}; //!< @brief request keys for http exiv2 handler and time-out

// *****************************************************************************
// free functions
std::string getEnv(int env_var)
{
// this check is relying on undefined behavior and might not be effective
Expand Down Expand Up @@ -140,14 +148,10 @@ namespace Exiv2 {
}

// https://stackoverflow.com/questions/342409/how-do-i-base64-encode-decode-in-c
static char base64_encode[]={'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'};
static constexpr char base64_encode[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};

int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize) {
auto encoding_table = (char*)base64_encode;
Expand Down Expand Up @@ -183,7 +187,7 @@ namespace Exiv2 {
size_t input_length = in ? ::strlen(in) : 0;
if (!in || input_length % 4 != 0) return result;

auto encoding_table = (unsigned char*)base64_encode;
auto encoding_table = reinterpret_cast<const unsigned char*>(base64_encode);
unsigned char decoding_table[256];
for (unsigned char i = 0; i < 64; i++)
decoding_table[encoding_table[i]] = i;
Expand Down
28 changes: 14 additions & 14 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <sys/types.h>
#include <stdio.h>
#include <array>
#include <cstdlib>
#include <time.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -98,27 +99,26 @@ static void Sleep(int millisecs)

////////////////////////////////////////
// code
static const char* httpTemplate =
"%s %s HTTP/%s\r\n" // $verb $page $version
"User-Agent: exiv2http/1.0.0\r\n"
"Accept: */*\r\n"
"Host: %s\r\n" // $servername
"%s" // $header
"\r\n"
;
static constexpr auto httpTemplate =
"%s %s HTTP/%s\r\n" // $verb $page $version
"User-Agent: exiv2http/1.0.0\r\n"
"Accept: */*\r\n"
"Host: %s\r\n" // $servername
"%s" // $header
"\r\n";

#define white(c) ((c == ' ') || (c == '\t'))

#define FINISH -999
#define OK(s) (200 <= s && s < 300)

const char* blankLines[] =
{ "\r\n\r\n" // this is the standard
, "\n\n" // this is commonly sent by CGI scripts
} ;
static constexpr std::array<const char*, 2> blankLines{
"\r\n\r\n", // this is the standard
"\n\n", // this is commonly sent by CGI scripts
};

int snooze = SNOOZE ;
int sleep_ = SLEEP ;
static constexpr int snooze = SNOOZE;
static int sleep_ = SLEEP;

static int forgive(int n,int& err)
{
Expand Down
85 changes: 42 additions & 43 deletions src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,49 +51,48 @@
// class member definitions

namespace Exiv2 {

const byte JpegBase::dht_ = 0xc4;
const byte JpegBase::dqt_ = 0xdb;
const byte JpegBase::dri_ = 0xdd;
const byte JpegBase::sos_ = 0xda;
const byte JpegBase::eoi_ = 0xd9;
const byte JpegBase::app0_ = 0xe0;
const byte JpegBase::app1_ = 0xe1;
const byte JpegBase::app2_ = 0xe2;
const byte JpegBase::app13_ = 0xed;
const byte JpegBase::com_ = 0xfe;

// Start of Frame markers, nondifferential Huffman-coding frames
const byte JpegBase::sof0_ = 0xc0; // start of frame 0, baseline DCT
const byte JpegBase::sof1_ = 0xc1; // start of frame 1, extended sequential DCT, Huffman coding
const byte JpegBase::sof2_ = 0xc2; // start of frame 2, progressive DCT, Huffman coding
const byte JpegBase::sof3_ = 0xc3; // start of frame 3, lossless sequential, Huffman coding

// Start of Frame markers, differential Huffman-coding frames
const byte JpegBase::sof5_ = 0xc5; // start of frame 5, differential sequential DCT, Huffman coding
const byte JpegBase::sof6_ = 0xc6; // start of frame 6, differential progressive DCT, Huffman coding
const byte JpegBase::sof7_ = 0xc7; // start of frame 7, differential lossless, Huffman coding

// Start of Frame markers, nondifferential arithmetic-coding frames
const byte JpegBase::sof9_ = 0xc9; // start of frame 9, extended sequential DCT, arithmetic coding
const byte JpegBase::sof10_ = 0xca; // start of frame 10, progressive DCT, arithmetic coding
const byte JpegBase::sof11_ = 0xcb; // start of frame 11, lossless sequential, arithmetic coding

// Start of Frame markers, differential arithmetic-coding frames
const byte JpegBase::sof13_ = 0xcd; // start of frame 13, differential sequential DCT, arithmetic coding
const byte JpegBase::sof14_ = 0xce; // start of frame 14, progressive DCT, arithmetic coding
const byte JpegBase::sof15_ = 0xcf; // start of frame 15, differential lossless, arithmetic coding

const char JpegBase::exifId_[] = "Exif\0\0";
const char JpegBase::jfifId_[] = "JFIF\0";
const char JpegBase::xmpId_[] = "http://ns.adobe.com/xap/1.0/\0";
const char JpegBase::iccId_[] = "ICC_PROFILE\0";

const char Photoshop::ps3Id_[] = "Photoshop 3.0\0";
const char* Photoshop::irbId_[] = {"8BIM", "AgHg", "DCSR", "PHUT"};
const char Photoshop::bimId_[] = "8BIM"; // deprecated
const uint16_t Photoshop::iptc_ = 0x0404;
const uint16_t Photoshop::preview_ = 0x040c;
constexpr byte JpegBase::dht_ = 0xc4;
constexpr byte JpegBase::dqt_ = 0xdb;
constexpr byte JpegBase::dri_ = 0xdd;
constexpr byte JpegBase::sos_ = 0xda;
constexpr byte JpegBase::eoi_ = 0xd9;
constexpr byte JpegBase::app0_ = 0xe0;
constexpr byte JpegBase::app1_ = 0xe1;
constexpr byte JpegBase::app2_ = 0xe2;
constexpr byte JpegBase::app13_ = 0xed;
constexpr byte JpegBase::com_ = 0xfe;

// Start of Frame markers, nondifferential Huffman-coding frames
constexpr byte JpegBase::sof0_ = 0xc0; // start of frame 0, baseline DCT
constexpr byte JpegBase::sof1_ = 0xc1; // start of frame 1, extended sequential DCT, Huffman coding
constexpr byte JpegBase::sof2_ = 0xc2; // start of frame 2, progressive DCT, Huffman coding
constexpr byte JpegBase::sof3_ = 0xc3; // start of frame 3, lossless sequential, Huffman coding

// Start of Frame markers, differential Huffman-coding frames
constexpr byte JpegBase::sof5_ = 0xc5; // start of frame 5, differential sequential DCT, Huffman coding
constexpr byte JpegBase::sof6_ = 0xc6; // start of frame 6, differential progressive DCT, Huffman coding
constexpr byte JpegBase::sof7_ = 0xc7; // start of frame 7, differential lossless, Huffman coding

// Start of Frame markers, nondifferential arithmetic-coding frames
constexpr byte JpegBase::sof9_ = 0xc9; // start of frame 9, extended sequential DCT, arithmetic coding
constexpr byte JpegBase::sof10_ = 0xca; // start of frame 10, progressive DCT, arithmetic coding
constexpr byte JpegBase::sof11_ = 0xcb; // start of frame 11, lossless sequential, arithmetic coding

// Start of Frame markers, differential arithmetic-coding frames
constexpr byte JpegBase::sof13_ = 0xcd; // start of frame 13, differential sequential DCT, arithmetic coding
constexpr byte JpegBase::sof14_ = 0xce; // start of frame 14, progressive DCT, arithmetic coding
constexpr byte JpegBase::sof15_ = 0xcf; // start of frame 15, differential lossless, arithmetic coding

constexpr const char* JpegBase::exifId_ = "Exif\0\0";
constexpr const char* JpegBase::jfifId_ = "JFIF\0";
constexpr const char* JpegBase::xmpId_ = "http://ns.adobe.com/xap/1.0/\0";
constexpr const char* JpegBase::iccId_ = "ICC_PROFILE\0";

constexpr const char* Photoshop::ps3Id_ = "Photoshop 3.0\0";
constexpr std::array<const char*, 4> Photoshop::irbId_{"8BIM", "AgHg", "DCSR", "PHUT"};
constexpr const char* Photoshop::bimId_ = "8BIM"; // deprecated
constexpr uint16_t Photoshop::iptc_ = 0x0404;
constexpr uint16_t Photoshop::preview_ = 0x040c;

static inline bool inRange(int lo,int value, int hi)
{
Expand Down
4 changes: 1 addition & 3 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2697,7 +2697,7 @@ namespace Exiv2 {
void decomposeKey(const std::string& key); //!< Misterious magic

// DATA
static const char* familyName_; //!< "Xmp"
static constexpr auto familyName_ = "Xmp"; //!< "Xmp"

std::string prefix_; //!< Prefix
std::string property_; //!< Property name
Expand All @@ -2714,8 +2714,6 @@ namespace Exiv2 {
prefix_ = prefix;
}

const char* XmpKey::Impl::familyName_ = "Xmp";

XmpKey::XmpKey(const std::string& key) : p_(new Impl)
{
p_->decomposeKey(key);
Expand Down
4 changes: 1 addition & 3 deletions src/tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ namespace Exiv2 {
//@}

// DATA
static const char* familyName_; //!< "Exif"
static constexpr auto familyName_ = "Exif"; //!< "Exif"

const TagInfo* tagInfo_{0}; //!< Tag info
uint16_t tag_{0}; //!< Tag value
Expand All @@ -229,8 +229,6 @@ namespace Exiv2 {
std::string key_; //!< %Key
};

const char* ExifKey::Impl::familyName_ = "Exif";

std::string ExifKey::Impl::tagName() const
{
if (tagInfo_ != 0 && tagInfo_->tag_ != 0xffff) {
Expand Down
8 changes: 4 additions & 4 deletions src/tiffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ namespace Exiv2 {
};

//! List of TIFF compression to MIME type mappings
MimeTypeList mimeTypeList[] = {
{ 32770, "image/x-samsung-srw" },
{ 34713, "image/x-nikon-nef" },
{ 65535, "image/x-pentax-pef" }
constexpr MimeTypeList mimeTypeList[] = {
{32770, "image/x-samsung-srw"},
{34713, "image/x-nikon-nef"},
{65535, "image/x-pentax-pef"},
};

std::string TiffImage::mimeType() const
Expand Down
Loading

0 comments on commit 43a91a4

Please sign in to comment.