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 <[email protected]>
  • Loading branch information
neheb committed May 20, 2021
1 parent 8dbc699 commit 924b3a6
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 167 deletions.
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -334,7 +334,7 @@ namespace Exiv2 {
virtual IptcKey* clone_() const;

// DATA
static const char* familyName_;
static constexpr auto familyName_ = "Iptc";

uint16_t tag_; //!< Tag value
uint16_t record_; //!< Record value
Expand Down
64 changes: 32 additions & 32 deletions include/exiv2/jpgimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ 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 uint16_t iptc_; //!< %Photoshop IPTC marker
static const uint16_t preview_; //!< %Photoshop preview marker
static constexpr auto ps3Id_ = "Photoshop 3.0\0"; //!< %Photoshop marker
static constexpr std::array<const char*, 4> irbId_{"8BIM", "AgHg", "DCSR", "PHUT"}; //!< %Photoshop IRB markers
static constexpr auto bimId_ = "8BIM"; //!< %Photoshop IRB marker (deprecated)
static constexpr uint16_t iptc_ = 0x0404; //!< %Photoshop IPTC marker
static constexpr uint16_t preview_ = 0x040c; //!< %Photoshop preview marker

/*!
@brief Checks an IRB
Expand Down Expand Up @@ -209,33 +209,33 @@ namespace Exiv2 {
//@}

// Constant Data
static const byte dht_; //!< JPEG DHT marker
static const byte dqt_; //!< JPEG DQT marker
static const byte dri_; //!< JPEG DRI marker
static const byte sos_; //!< JPEG SOS marker
static const byte eoi_; //!< JPEG EOI marker
static const byte app0_; //!< JPEG APP0 marker
static const byte app1_; //!< JPEG APP1 marker
static const byte app2_; //!< JPEG APP2 marker
static const byte app13_; //!< JPEG APP13 marker
static const byte com_; //!< JPEG Comment marker
static const byte sof0_; //!< JPEG Start-Of-Frame marker
static const byte sof1_; //!< JPEG Start-Of-Frame marker
static const byte sof2_; //!< JPEG Start-Of-Frame marker
static const byte sof3_; //!< JPEG Start-Of-Frame marker
static const byte sof5_; //!< JPEG Start-Of-Frame marker
static const byte sof6_; //!< JPEG Start-Of-Frame marker
static const byte sof7_; //!< JPEG Start-Of-Frame marker
static const byte sof9_; //!< JPEG Start-Of-Frame marker
static const byte sof10_; //!< JPEG Start-Of-Frame marker
static const byte sof11_; //!< JPEG Start-Of-Frame marker
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 constexpr byte dht_ = 0xc4; //!< JPEG DHT marker
static constexpr byte dqt_ = 0xdb; //!< JPEG DQT marker
static constexpr byte dri_ = 0xdd; //!< JPEG DRI marker
static constexpr byte sos_ = 0xda; //!< JPEG SOS marker
static constexpr byte eoi_ = 0xd9; //!< JPEG EOI marker
static constexpr byte app0_ = 0xe0; //!< JPEG APP0 marker
static constexpr byte app1_ = 0xe1; //!< JPEG APP1 marker
static constexpr byte app2_ = 0xe2; //!< JPEG APP2 marker
static constexpr byte app13_ = 0xed; //!< JPEG APP13 marker
static constexpr byte com_ = 0xfe; //!< JPEG Comment marker
static constexpr byte sof0_ = 0xc0; //!< JPEG Start-Of-Frame marker
static constexpr byte sof1_ = 0xc1; //!< JPEG Start-Of-Frame marker
static constexpr byte sof2_ = 0xc2; //!< JPEG Start-Of-Frame marker
static constexpr byte sof3_ = 0xc3; //!< JPEG Start-Of-Frame marker
static constexpr byte sof5_ = 0xc5; //!< JPEG Start-Of-Frame marker
static constexpr byte sof6_ = 0xc6; //!< JPEG Start-Of-Frame marker
static constexpr byte sof7_ = 0xc7; //!< JPEG Start-Of-Frame marker
static constexpr byte sof9_ = 0xc9; //!< JPEG Start-Of-Frame marker
static constexpr byte sof10_ = 0xca; //!< JPEG Start-Of-Frame marker
static constexpr byte sof11_ = 0xcb; //!< JPEG Start-Of-Frame marker
static constexpr byte sof13_ = 0xcd; //!< JPEG Start-Of-Frame marker
static constexpr byte sof14_ = 0xce; //!< JPEG Start-Of-Frame marker
static constexpr byte sof15_ = 0xcf; //!< JPEG Start-Of-Frame marker
static constexpr auto exifId_ = "Exif\0\0"; //!< Exif identifier
static constexpr auto jfifId_ = "JFIF\0"; //!< JFIF identifier
static constexpr auto xmpId_ = "http://ns.adobe.com/xap/1.0/\0"; //!< XMP packet identifier
static constexpr auto iccId_ = "ICC_PROFILE\0"; //!< 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 constexpr int WEBP_TAG_SIZE = 0x4;
static constexpr int WEBP_VP8X_ICC_BIT = 0x20;
static constexpr int WEBP_VP8X_ALPHA_BIT = 0x10;
static constexpr int WEBP_VP8X_EXIF_BIT = 0x8;
static constexpr int WEBP_VP8X_XMP_BIT = 0x4;
static constexpr auto WEBP_CHUNK_HEADER_VP8X = "VP8X";
static constexpr auto WEBP_CHUNK_HEADER_VP8L = "VP8L";
static constexpr auto WEBP_CHUNK_HEADER_VP8 = "VP8 ";
static constexpr auto WEBP_CHUNK_HEADER_ANMF = "ANMF";
static constexpr auto WEBP_CHUNK_HEADER_ANIM = "ANIM";
static constexpr auto WEBP_CHUNK_HEADER_ICCP = "ICCP";
static constexpr auto WEBP_CHUNK_HEADER_EXIF = "EXIF";
static constexpr auto WEBP_CHUNK_HEADER_XMP = "XMP ";

}; //Class WebPImage

Expand Down
2 changes: 0 additions & 2 deletions src/cr2header_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,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: 7 additions & 8 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"),
const DataSet unknownDataSet{0xffff, "Unknown dataset", N_("Unknown dataset"),
N_("Unknown dataset"),
false, true, 0, 0xffffffff, Exiv2::string,
IptcDataSets::invalidRecord,
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 Expand Up @@ -551,8 +552,6 @@ namespace Exiv2 {
}
} // IptcDataSets::dataSetList

const char* IptcKey::familyName_ = "Iptc";

IptcKey::IptcKey(std::string key) : key_(std::move(key))
{
decomposeKey();
Expand Down
24 changes: 11 additions & 13 deletions src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@
#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 +142,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 +181,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
27 changes: 13 additions & 14 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,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
44 changes: 0 additions & 44 deletions src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,50 +51,6 @@
// 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;

static inline bool inRange(int lo,int value, int hi)
{
return lo<=value && value <= 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 924b3a6

Please sign in to comment.