Skip to content

Commit 17fe9da

Browse files
committed
Fix conversion warnings gbak (burp)
+ make some things constexpr
1 parent d28b3e4 commit 17fe9da

File tree

4 files changed

+63
-66
lines changed

4 files changed

+63
-66
lines changed

src/burp/burp.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,14 @@ using namespace Firebird;
8888
using MsgFormat::SafeArg;
8989
using namespace Burp;
9090

91-
const char* fopen_write_type = "w";
92-
const char* fopen_read_type = "r";
91+
inline constexpr const char* fopen_write_type = "w";
92+
inline constexpr const char* fopen_read_type = "r";
9393

94-
const int open_mask = 0666;
95-
const char switch_char = '-';
94+
inline constexpr int open_mask = 0666;
95+
inline constexpr char switch_char = '-';
9696

97-
98-
const char* const output_suppress = "SUPPRESS";
99-
const int MIN_VERBOSE_INTERVAL = 100;
97+
inline constexpr const char* output_suppress = "SUPPRESS";
98+
inline constexpr int MIN_VERBOSE_INTERVAL = 100;
10099

101100
enum gbak_action
102101
{
@@ -121,9 +120,9 @@ static void processFetchPass(const SCHAR*& password, int& itr, const int argc, F
121120

122121

123122
// fil.fil_length is FB_UINT64
124-
const ULONG KBYTE = 1024;
125-
const ULONG MBYTE = KBYTE * KBYTE;
126-
const ULONG GBYTE = MBYTE * KBYTE;
123+
inline constexpr ULONG KBYTE = 1024;
124+
inline constexpr ULONG MBYTE = 1024 * KBYTE;
125+
inline constexpr ULONG GBYTE = 1024 * MBYTE;
127126

128127
// Must be consistent with enum BurpGlobals::StatCounter
129128
struct StatFormat
@@ -132,8 +131,8 @@ struct StatFormat
132131
const char* format;
133132
char width;
134133
};
135-
static const char* STAT_CHARS = "TDRW";
136-
static const StatFormat STAT_FORMATS[] =
134+
static inline constexpr const char* STAT_CHARS = "TDRW";
135+
static inline constexpr StatFormat STAT_FORMATS[] =
137136
{
138137
{"time", "%4lu.%03u ", 9},
139138
{"delta", "%2lu.%03u ", 7},
@@ -2607,7 +2606,7 @@ static ULONG get_size(const SCHAR* string, burp_fil* file)
26072606
* restoring to multiple files
26082607
*
26092608
**********************************************/
2610-
const FB_UINT64 overflow = MAX_UINT64 / 10 - 1;
2609+
constexpr FB_UINT64 overflow = MAX_UINT64 / 10 - 1;
26112610
UCHAR c;
26122611
FB_UINT64 size = 0;
26132612
bool digit = false;
@@ -2749,7 +2748,7 @@ namespace // for local symbols
27492748
if (!matcher)
27502749
return NOT_SET;
27512750

2752-
return matcher->matches(name, strlen(name))? MATCH : NOT_MATCH;
2751+
return matcher->matches(name, fb_strlen(name)) ? MATCH : NOT_MATCH;
27532752
}
27542753
}
27552754

@@ -2829,7 +2828,7 @@ void BurpGlobals::print_stats(USHORT number)
28292828

28302829
burp_output(false, " ");
28312830

2832-
const int time_mask = (1 << TIME_TOTAL) | (1 << TIME_DELTA);
2831+
constexpr int time_mask = (1 << TIME_TOTAL) | (1 << TIME_DELTA);
28332832
if (gbl_stat_flags & time_mask)
28342833
{
28352834
const SINT64 t0 = fb_utils::query_performance_counter();

src/burp/burp.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@
6767
//#define COMPRESS_DEBUG 1
6868
#endif // WIRE_COMPRESS_SUPPORT
6969

70-
const int GDS_NAME_LEN = METADATA_IDENTIFIER_CHAR_LEN * 4 /* max bytes per char */ + 1;
71-
typedef TEXT GDS_NAME[GDS_NAME_LEN];
70+
inline constexpr int GDS_NAME_LEN = METADATA_IDENTIFIER_CHAR_LEN * 4 /* max bytes per char */ + 1;
71+
typedef TEXT GDS_NAME[GDS_NAME_LEN];
7272

7373
enum redirect_vals {
7474
NOREDIRECT = 0,
7575
REDIRECT = 1,
7676
NOOUTPUT = 2
7777
};
7878

79-
static const int burp_msg_fac = 12;
79+
static inline constexpr int burp_msg_fac = FB_IMPL_MSG_FACILITY_GBAK;
8080

8181
// Record types in backup file
8282

@@ -213,15 +213,15 @@ Version 12: FB6.0.
213213
Schemas.
214214
*/
215215

216-
const int ATT_BACKUP_FORMAT = 12;
216+
inline constexpr int ATT_BACKUP_FORMAT = 12;
217217

218218
// max array dimension
219219

220-
const int MAX_DIMENSION = 16;
220+
inline constexpr int MAX_DIMENSION = 16;
221221

222-
const int SERIES = 1;
222+
inline constexpr int SERIES = 1;
223223

224-
const USHORT MAX_UPDATE_DBKEY_RECURSION_DEPTH = 16;
224+
inline constexpr USHORT MAX_UPDATE_DBKEY_RECURSION_DEPTH = 16;
225225

226226

227227
enum att_type {
@@ -715,13 +715,13 @@ enum trig_t {
715715
// these types to go away when recognized by gpre as
716716
// <relation>.<field>.<type> some time in the future
717717

718-
const int TRIG_TYPE_PRE_STORE = 1;
719-
const int TRIG_TYPE_PRE_MODIFY = 3;
720-
const int TRIG_TYPE_POST_ERASE = 6;
718+
inline constexpr int TRIG_TYPE_PRE_STORE = 1;
719+
inline constexpr int TRIG_TYPE_PRE_MODIFY = 3;
720+
inline constexpr int TRIG_TYPE_POST_ERASE = 6;
721721

722722
// default trigger name templates
723723

724-
const int TRIGGER_SEQUENCE_DEFAULT = 0;
724+
inline constexpr int TRIGGER_SEQUENCE_DEFAULT = 0;
725725

726726
// common structure definitions
727727

@@ -852,7 +852,7 @@ struct burp_meta_obj
852852

853853
// CVC: Could use MAXPATHLEN, but what about restoring in a different system?
854854
// I need to review if we tolerate different lengths for different OS's here.
855-
const unsigned int MAX_FILE_NAME_SIZE = 256;
855+
inline constexpr unsigned int MAX_FILE_NAME_SIZE = 256;
856856

857857
#include "../burp/std_desc.h"
858858

@@ -936,9 +936,9 @@ struct burp_act
936936
act_t act_action;
937937
};
938938

939-
const size_t ACT_LEN = sizeof(burp_act);
939+
inline constexpr size_t ACT_LEN = sizeof(burp_act);
940940

941-
const ULONG MAX_LENGTH = ~FB_CONST64(0); // Keep in sync with burp_fil.fil_length
941+
inline constexpr ULONG MAX_LENGTH = ~FB_CONST64(0); // Keep in sync with burp_fil.fil_length
942942

943943
// This structure has been cloned from spit.cpp
944944

@@ -958,12 +958,12 @@ struct hdr_split
958958
// NOTE: size of the hdr_split_tag and HDR_SPLIT_TAG must be the same and equal
959959
// to 18. Otherwise we will not be able to join the gbk files v5.x
960960

961-
const size_t HDR_SPLIT_SIZE = sizeof(hdr_split);
962-
static const char HDR_SPLIT_TAG5[] = "InterBase/gsplit, ";
963-
static const char HDR_SPLIT_TAG6[] = "InterBase/gbak, ";
961+
inline constexpr size_t HDR_SPLIT_SIZE = sizeof(hdr_split);
962+
static inline constexpr char HDR_SPLIT_TAG5[] = "InterBase/gsplit, ";
963+
static inline constexpr char HDR_SPLIT_TAG6[] = "InterBase/gbak, ";
964964
// CVC: Don't convert to const char* or you will have to fix the sizeof()'s!!!
965965
#define HDR_SPLIT_TAG HDR_SPLIT_TAG6
966-
const FB_UINT64 MIN_SPLIT_SIZE = FB_CONST64(2048); // bytes
966+
inline constexpr FB_UINT64 MIN_SPLIT_SIZE = FB_CONST64(2048); // bytes
967967

968968

969969
// Global switches and data
@@ -1285,7 +1285,7 @@ class BurpGlobals : public Firebird::ThreadData, public GblPool
12851285
void BURP_exit_local(int code, BurpGlobals* tdgbl);
12861286

12871287
// database is not on-line due to failure to activate one or more indices
1288-
const int FINI_DB_NOT_ONLINE = 2;
1288+
inline constexpr int FINI_DB_NOT_ONLINE = 2;
12891289

12901290
/* Burp will always write a backup in multiples of the following number
12911291
* of bytes. The initial value is the smallest which ensures that writes
@@ -1296,8 +1296,8 @@ const int FINI_DB_NOT_ONLINE = 2;
12961296
* bit masking.
12971297
*/
12981298

1299-
const int BURP_BLOCK = 512;
1300-
inline static ULONG BURP_UP_TO_BLOCK(const ULONG size)
1299+
inline constexpr int BURP_BLOCK = 512;
1300+
static inline constexpr ULONG BURP_UP_TO_BLOCK(const ULONG size)
13011301
{
13021302
return (((size) + BURP_BLOCK - 1) & ~(BURP_BLOCK - 1));
13031303
}
@@ -1306,11 +1306,11 @@ inline static ULONG BURP_UP_TO_BLOCK(const ULONG size)
13061306
// so that other files can see them for multivolume opens
13071307

13081308
#ifdef WIN_NT
1309-
static const ULONG MODE_READ = GENERIC_READ;
1310-
static const ULONG MODE_WRITE = GENERIC_WRITE;
1309+
static inline constexpr ULONG MODE_READ = GENERIC_READ;
1310+
static inline constexpr ULONG MODE_WRITE = GENERIC_WRITE;
13111311
#else
1312-
static const ULONG MODE_READ = O_RDONLY;
1313-
static const ULONG MODE_WRITE = O_WRONLY | O_CREAT;
1312+
static inline constexpr ULONG MODE_READ = O_RDONLY;
1313+
static inline constexpr ULONG MODE_WRITE = O_WRONLY | O_CREAT;
13141314
#endif
13151315

13161316

src/burp/mvol.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ using MsgFormat::SafeArg;
7272
using Firebird::FbLocalStatus;
7373
using namespace Burp;
7474

75-
const int open_mask = 0666;
75+
inline constexpr int open_mask = 0666;
7676

7777
#ifdef WIN_NT
78-
const char* TERM_INPUT = "CONIN$";
79-
const char* TERM_OUTPUT = "CONOUT$";
78+
inline constexpr const char* TERM_INPUT = "CONIN$";
79+
inline constexpr const char* TERM_OUTPUT = "CONOUT$";
8080
#else
81-
const char* TERM_INPUT = "/dev/tty";
82-
const char* TERM_OUTPUT = "/dev/tty";
81+
inline constexpr const char* TERM_INPUT = "/dev/tty";
82+
inline constexpr const char* TERM_OUTPUT = "/dev/tty";
8383
#endif
8484

8585
static int mvol_read(int*, UCHAR**);
@@ -91,8 +91,8 @@ static FB_UINT64 mvol_fini_write(BurpGlobals*, int*, UCHAR**);
9191
static void mvol_init_write(BurpGlobals*, const char*, int*, UCHAR**);
9292
static void brio_fini(BurpGlobals*);
9393

94-
static const int MAX_HEADER_SIZE = 512;
95-
static const int ZC_BUFSIZE = IO_BUFFER_SIZE;
94+
static inline constexpr int MAX_HEADER_SIZE = 512;
95+
static inline constexpr int ZC_BUFSIZE = IO_BUFFER_SIZE;
9696

9797
static inline int get(BurpGlobals* tdgbl)
9898
{
@@ -101,7 +101,7 @@ static inline int get(BurpGlobals* tdgbl)
101101
return (--tdgbl->mvol_io_cnt >= 0 ? *tdgbl->mvol_io_ptr++ : 255);
102102
}
103103

104-
static inline void put(BurpGlobals* tdgbl, UCHAR c)
104+
static inline void put(BurpGlobals* tdgbl, UCHAR c) noexcept
105105
{
106106
--tdgbl->mvol_io_cnt;
107107
*tdgbl->mvol_io_ptr++ = c;
@@ -132,7 +132,7 @@ static void zip_write_block(BurpGlobals*, const UCHAR*, FB_SIZE_T, bool);
132132
static ULONG unzip_read_block(BurpGlobals*, UCHAR*, FB_SIZE_T);
133133

134134
// Portion of data passed to crypt plugin
135-
const ULONG CRYPT_STEP = 256;
135+
inline constexpr ULONG CRYPT_STEP = 256;
136136

137137
class DbInfo final : public Firebird::RefCntIface<Firebird::IDbCryptInfoImpl<DbInfo, Firebird::CheckStatusWrapper> >
138138
{
@@ -1706,11 +1706,11 @@ static void prompt_for_name(SCHAR* name, int length)
17061706
//
17071707
// Write an attribute starting with a null terminated string.
17081708
//
1709-
static void put_asciz( SCHAR attribute, const TEXT* str)
1709+
static void put_asciz(SCHAR attribute, const TEXT* str)
17101710
{
17111711
BurpGlobals* tdgbl = BurpGlobals::getSpecific();
17121712

1713-
USHORT l = strlen(str);
1713+
USHORT l = static_cast<USHORT>(strlen(str));
17141714
if (l > MAX_UCHAR)
17151715
{
17161716
BURP_print(false, 343, SafeArg() << int(attribute) << "put_asciz()" << USHORT(MAX_UCHAR));

src/burp/split/spit.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,18 @@
2525
* Contributor(s): ______________________________________.
2626
*/
2727

28-
const char BLANK = ' ';
29-
const int FILE_IS_FULL = -9;
30-
//const int FILE_NM_ARR_LEN = 20;
31-
//const char* GSPLIT_HDR_REC_NM = "InterBase/Gsplit";
28+
inline constexpr char BLANK = ' ';
29+
inline constexpr int FILE_IS_FULL = -9;
3230

33-
const int K_BYTES = 1024;
34-
const int IO_BUFFER_SIZE = (16 * K_BYTES);
35-
const int SVC_IO_BUFFER_SIZE = (16 * (IO_BUFFER_SIZE));
36-
const int GBAK_IO_BUFFER_SIZE = SVC_IO_BUFFER_SIZE;
31+
inline constexpr int K_BYTES = 1024;
32+
inline constexpr int M_BYTES = 1024 * K_BYTES;
33+
inline constexpr int G_BYTES = 1024 * M_BYTES;
34+
inline constexpr int IO_BUFFER_SIZE = 16 * K_BYTES;
35+
inline constexpr int SVC_IO_BUFFER_SIZE = 16 * IO_BUFFER_SIZE;
36+
inline constexpr int GBAK_IO_BUFFER_SIZE = SVC_IO_BUFFER_SIZE;
3737

38-
const int M_BYTES = (K_BYTES * K_BYTES);
39-
const int G_BYTES = (K_BYTES * M_BYTES);
40-
const size_t MAX_FILE_NM_LEN = 27; // size of header_rec.fl_name
41-
const int MAX_NUM_OF_FILES = 9999;
42-
const int MIN_FILE_SIZE = M_BYTES;
43-
const char NEW_LINE = '\n';
44-
const char TERMINAL = '\0';
38+
inline constexpr size_t MAX_FILE_NM_LEN = 27; // size of header_rec.fl_name
39+
inline constexpr int MAX_NUM_OF_FILES = 9999;
40+
inline constexpr int MIN_FILE_SIZE = M_BYTES;
41+
inline constexpr char NEW_LINE = '\n';
42+
inline constexpr char TERMINAL = '\0';

0 commit comments

Comments
 (0)