fix: mark all Idxheader packed explicitly
Some checks failed
SonarCloud / Build and analyze (push) Has been cancelled

This commit is contained in:
shenleban tongying 2024-09-25 06:09:01 -04:00 committed by GitHub
parent 2a918d5fdd
commit 58f346f23e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 76 additions and 111 deletions

View file

@ -67,31 +67,23 @@ struct AAR_header
char indexItemFormat[ 4 ];
char keyLengthFormat[ 2 ];
char articleLengthFormat[ 2 ];
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( AAR_header ) == 1 );
struct IndexElement
{
quint32 wordOffset;
quint32 articleOffset;
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IndexElement ) == 1 );
struct IndexElement64
{
quint32 wordOffset;
quint64 articleOffset;
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IndexElement64 ) == 1 );
enum {
Signature = 0x58524141, // AARX on little-endian, XRAA on big-endian
@ -109,12 +101,8 @@ struct IdxHeader
quint32 articleCount;
quint32 langFrom; // Source language
quint32 langTo; // Target language
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile )

View file

@ -53,6 +53,8 @@ enum {
CurrentFormatVersion = 19 + BtreeIndexing::FormatVersion
};
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, BGLX
@ -77,11 +79,9 @@ struct IdxHeader
uint32_t iconSize; // Size of the icon in the chunks' storage, 0 = no icon
uint32_t descriptionAddress; // Address of the dictionary description in the chunks' storage
uint32_t descriptionSize; // Size of the description in the chunks' storage, 0 = no description
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile )
{

View file

@ -55,6 +55,8 @@ enum {
CurrentFormatVersion = 5 + BtreeIndexing::FormatVersion + Folding::Version
};
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, DCDX
@ -65,11 +67,10 @@ struct IdxHeader
uint32_t indexRootOffset;
uint32_t langFrom; // Source language
uint32_t langTo; // Target language
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile )
{

View file

@ -86,6 +86,8 @@ enum {
CurrentFtsIndexVersion = 7
};
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, DSLX
@ -93,7 +95,7 @@ struct IdxHeader
uint32_t zipSupportVersion; // Zip support version -- narrows down reindexing
// when it changes only for dictionaries with the
// zip files
int dslEncoding; // Which encoding is used for the file indexed
uint32_t dslEncoding; // Which encoding is used for the file indexed
uint32_t chunksOffset; // The offset to chunks' storage
uint32_t hasAbrv; // Non-zero means file has abrvs at abrvAddress
uint32_t abrvAddress; // Address of abrv map in the chunked storage
@ -109,11 +111,10 @@ struct IdxHeader
uint32_t zipIndexBtreeMaxElements; // Two fields from IndexInfo of the zip
// resource index.
uint32_t zipIndexRootOffset;
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
struct InsidedCard
{

View file

@ -60,13 +60,9 @@ struct IdxHeader
quint32 nameSize;
quint32 langFrom; // Source language
quint32 langTo; // Target language
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
#pragma pack( pop )
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile )
{

View file

@ -304,6 +304,8 @@ enum {
CurrentFtsIndexVersion = 1
};
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, GLSX
@ -311,7 +313,7 @@ struct IdxHeader
uint32_t zipSupportVersion; // Zip support version -- narrows down reindexing
// when it changes only for dictionaries with the
// zip files
int glsEncoding; // Which encoding is used for the file indexed
uint32_t glsEncoding; // Which encoding is used for the file indexed
uint32_t chunksOffset; // The offset to chunks' storage
uint32_t indexBtreeMaxElements; // Two fields from IndexInfo
uint32_t indexRootOffset;
@ -324,11 +326,9 @@ struct IdxHeader
uint32_t zipIndexBtreeMaxElements; // Two fields from IndexInfo of the zip
// resource index.
uint32_t zipIndexRootOffset;
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile, bool hasZipFile )
{

View file

@ -49,6 +49,8 @@ enum {
CurrentFormatVersion = 5
};
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, BGLX
@ -57,11 +59,9 @@ struct IdxHeader
uint32_t vorbisOffset; // Offset of the vorbis file which contains all snds
uint32_t indexBtreeMaxElements; // Two fields from IndexInfo
uint32_t indexRootOffset;
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile )
{

View file

@ -62,6 +62,8 @@ enum {
DEF_EX( exCorruptDictionary, "dictionary file was tampered or corrupted", std::exception )
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, MDIC
@ -92,11 +94,9 @@ struct IdxHeader
uint32_t mddIndexInfosOffset; // address of IndexInfos for resource files (.mdd)
uint32_t mddIndexInfosCount; // count of IndexInfos for resource files
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
// A helper method to read resources from .mdd file
class IndexedMdd: public BtreeIndexing::BtreeIndex

View file

@ -68,22 +68,16 @@ struct DCT_header
uint32_t shortIndexOffset;
uint32_t fullIndexOffset;
uint32_t articlesOffset;
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( DCT_header ) == 1 );
struct IndexElement
{
uint16_t nextWord;
uint16_t previousWord;
uint32_t articleOffset;
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IndexElement ) == 1 );
enum {
Signature = 0x43494453, // SDIC on little-endian, CIDS on big-endian
@ -102,12 +96,8 @@ struct IdxHeader
uint32_t compressionType; // Data compression in file. 0 - no compression, 1 - zip, 2 - bzip2
uint32_t langFrom; // Source language
uint32_t langTo; // Target language
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile )

View file

@ -62,13 +62,13 @@ DEF_EX_STR( exNoCodecFound, "No text codec found", Dictionary::Ex )
DEF_EX( exUserAbort, "User abort", Dictionary::Ex )
DEF_EX( exNoResource, "No resource found", Dictionary::Ex )
#pragma pack( push, 1 )
enum {
Signature = 0x58424C53, // SLBX on little-endian, XBLS on big-endian
CurrentFormatVersion = 2 + BtreeIndexing::FormatVersion + Folding::Version
};
#pragma pack( push, 1 )
struct IdxHeader
{
quint32 signature; // First comes the signature, SLBX
@ -81,13 +81,9 @@ struct IdxHeader
quint32 articleCount;
quint32 langFrom; // Source language
quint32 langTo; // Target language
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
#pragma pack( pop )
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
const char SLOB_MAGIC[ 8 ] = { 0x21, 0x2d, 0x31, 0x53, 0x4c, 0x4f, 0x42, 0x1f };

View file

@ -36,6 +36,7 @@ enum {
CurrentFormatVersion = 1 + BtreeIndexing::FormatVersion + Folding::Version
};
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, SDRX
@ -44,11 +45,9 @@ struct IdxHeader
uint32_t chunksOffset; // The offset to chunks' storage
uint32_t indexBtreeMaxElements; // Two fields from IndexInfo
uint32_t indexRootOffset;
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile )
{

View file

@ -93,6 +93,7 @@ enum {
CurrentFormatVersion = 9 + BtreeIndexing::FormatVersion + Folding::Version
};
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, SIDX
@ -110,10 +111,10 @@ struct IdxHeader
uint32_t zipIndexBtreeMaxElements; // Two fields from IndexInfo of the zip
// resource index.
uint32_t zipIndexRootOffset;
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
;
bool indexIsOldOrBad( string const & indexFile )

View file

@ -94,6 +94,7 @@ enum ArticleFormat {
Logical = 2
};
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, XDXF
@ -118,11 +119,9 @@ struct IdxHeader
// resource index.
uint32_t zipIndexRootOffset;
uint32_t revisionNumber; // Format revision
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile )
{

View file

@ -66,13 +66,12 @@ DEF_EX( exUserAbort, "User abort", Dictionary::Ex )
using ZimFile = zim::Archive;
#pragma pack( push, 1 )
enum {
Signature = 0x584D495A, // ZIMX on little-endian, XMIZ on big-endian
CurrentFormatVersion = 4 + BtreeIndexing::FormatVersion + Folding::Version
};
#pragma pack( push, 1 )
struct IdxHeader
{
quint32 signature; // First comes the signature, ZIMX
@ -87,12 +86,8 @@ struct IdxHeader
quint32 descriptionPtr;
quint32 langFrom; // Source language
quint32 langTo; // Target language
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
// Some supporting functions

View file

@ -45,6 +45,7 @@ enum {
CurrentFormatVersion = 6 + BtreeIndexing::FormatVersion
};
#pragma pack( push, 1 )
struct IdxHeader
{
uint32_t signature; // First comes the signature, ZIPS
@ -53,11 +54,9 @@ struct IdxHeader
uint32_t indexBtreeMaxElements; // Two fields from IndexInfo
uint32_t indexRootOffset;
uint32_t chunksOffset; // The offset to chunks' storage
}
#ifndef _MSC_VER
__attribute__( ( packed ) )
#endif
;
};
static_assert( alignof( IdxHeader ) == 1 );
#pragma pack( pop )
bool indexIsOldOrBad( string const & indexFile )
{