Skip to content

Commit 234c9cc

Browse files
committed
Fix -Wswitch and -Wparentheses warnings in backup and restore
+ constexpr
1 parent 8c95ad3 commit 234c9cc

File tree

2 files changed

+46
-44
lines changed

2 files changed

+46
-44
lines changed

src/burp/backup.epp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,25 @@ UCHAR debug_on = 0; // able to turn this on in debug mode
164164
#endif
165165

166166

167-
const UCHAR blob_items[] =
167+
constexpr UCHAR blob_items[] =
168168
{
169169
isc_info_blob_max_segment,
170170
isc_info_blob_num_segments,
171171
isc_info_blob_type,
172172
isc_info_blob_total_length
173173
};
174-
const UCHAR blr_items[] =
174+
constexpr UCHAR blr_items[] =
175175
{
176176
isc_info_blob_max_segment,
177177
isc_info_blob_total_length
178178
};
179-
const UCHAR source_items[] =
179+
constexpr UCHAR source_items[] =
180180
{
181181
isc_info_blob_max_segment,
182182
isc_info_blob_total_length,
183183
isc_info_blob_num_segments
184184
};
185-
const UCHAR db_info_items[] =
185+
constexpr UCHAR db_info_items[] =
186186
{
187187
isc_info_db_sql_dialect,
188188
isc_info_page_size,
@@ -194,12 +194,12 @@ const UCHAR db_info_items[] =
194194
fb_info_replica_mode,
195195
isc_info_end
196196
};
197-
const UCHAR limbo_tpb[] =
197+
constexpr UCHAR limbo_tpb[] =
198198
{
199199
isc_tpb_version1,
200200
isc_tpb_ignore_limbo
201201
};
202-
const UCHAR limbo_nau_tpb[] =
202+
constexpr UCHAR limbo_nau_tpb[] =
203203
{
204204
isc_tpb_version1,
205205
isc_tpb_ignore_limbo,
@@ -291,7 +291,7 @@ int BACKUP_backup(const TEXT* dbb_file, const TEXT* file_name)
291291
// detect if MAKE_DBKEY is supported and decide kind of read relation query
292292
if (tdgbl->gbl_sw_par_workers > 1)
293293
{
294-
const char* sql = "SELECT MAKE_DBKEY(0, 0) FROM RDB$DATABASE";
294+
constexpr const char* sql = "SELECT MAKE_DBKEY(0, 0) FROM RDB$DATABASE";
295295
IStatement* stmt = DB->prepare(fbStatus, gds_trans, 0, sql, 3, 0);
296296
if (fbStatus->getState() & IStatus::RESULT_ERROR)
297297
{
@@ -1945,7 +1945,7 @@ void put_relation( burp_rel* relation)
19451945

19461946
// sort the list of fields into three lists, depending on alignment
19471947
burp_fld* field;
1948-
for (field = fields; field = fields;)
1948+
for (field = fields; (field = fields);)
19491949
{
19501950
fields = field->fld_next;
19511951
USHORT l = field->fld_length;
@@ -1977,28 +1977,28 @@ void put_relation( burp_rel* relation)
19771977
// re-create (approximately) the original order of the fields. This is
19781978
// not strictly required, but it certainly is polite.
19791979

1980-
while (field = unaligned)
1980+
while ((field = unaligned))
19811981
{
19821982
unaligned = field->fld_next;
19831983
field->fld_next = relation->rel_fields;
19841984
relation->rel_fields = field;
19851985
}
19861986

1987-
while (field = aligned)
1987+
while ((field = aligned))
19881988
{
19891989
aligned = field->fld_next;
19901990
field->fld_next = relation->rel_fields;
19911991
relation->rel_fields = field;
19921992
}
19931993

1994-
while (field = aligned4)
1994+
while ((field = aligned4))
19951995
{
19961996
aligned4 = field->fld_next;
19971997
field->fld_next = relation->rel_fields;
19981998
relation->rel_fields = field;
19991999
}
20002000

2001-
while (field = aligned8)
2001+
while ((field = aligned8))
20022002
{
20032003
aligned8 = field->fld_next;
20042004
field->fld_next = relation->rel_fields;
@@ -2628,12 +2628,12 @@ void write_database( const TEXT* dbb_file)
26282628
break;
26292629

26302630
case isc_info_no_reserve:
2631-
if (no_reserve = (USHORT) gds__vax_integer(d, length))
2631+
if ((no_reserve = (USHORT) gds__vax_integer(d, length)) != 0)
26322632
put_int32(att_no_reserve, no_reserve);
26332633
break;
26342634

26352635
case isc_info_set_page_buffers:
2636-
if (page_buffers = gds__vax_integer(d, length))
2636+
if ((page_buffers = gds__vax_integer(d, length)) != 0)
26372637
put_int32(att_page_buffers, page_buffers);
26382638
break;
26392639

@@ -2646,12 +2646,12 @@ void write_database( const TEXT* dbb_file)
26462646
break;
26472647

26482648
case isc_info_db_read_only:
2649-
if (db_read_only = (USHORT) gds__vax_integer(d, length))
2649+
if ((db_read_only = (USHORT) gds__vax_integer(d, length)) != 0)
26502650
put_int32(att_db_read_only, db_read_only);
26512651
break;
26522652

26532653
case fb_info_replica_mode:
2654-
if (replica_mode = (USHORT) gds__vax_integer(d, length))
2654+
if ((replica_mode = (USHORT) gds__vax_integer(d, length)) != 0)
26552655
put_int32(att_replica_mode, replica_mode);
26562656
break;
26572657

@@ -4335,7 +4335,7 @@ void write_sql_roles()
43354335
put_source_blob (att_role_description, att_role_description, X.RDB$DESCRIPTION);
43364336
}
43374337

4338-
const UCHAR ll = sizeof(X.RDB$SYSTEM_PRIVILEGES);
4338+
constexpr UCHAR ll = sizeof(X.RDB$SYSTEM_PRIVILEGES);
43394339
put(tdgbl, att_role_sys_priveleges);
43404340
put(tdgbl, ll);
43414341
put_block(tdgbl, (const UCHAR*) (X.RDB$SYSTEM_PRIVILEGES), ll);

src/burp/restore.epp

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ DATABASE DB = STATIC FILENAME "yachts.lnk";
9393
namespace // unnamed, private
9494
{
9595

96-
const int DEFERRED_ACTIVE = 3; // RDB$INDEX_INACTIVE setting for Foreign Keys
96+
constexpr int DEFERRED_ACTIVE = 3; // RDB$INDEX_INACTIVE setting for Foreign Keys
9797
// This setting is used temporarily while
9898
// restoring a database. This was required
9999
// in order to differentiate a partial
@@ -193,7 +193,7 @@ UCHAR debug_on = 0; // able to turn this on in the debugger
193193
#endif
194194

195195
#ifdef sparc
196-
const SSHORT old_sparcs[] =
196+
constexpr SSHORT old_sparcs[] =
197197
{0, 0, 0, 2, 0, 0, 0, 0, 2, 4, 4, 4, 8, 8, 0, 0, 8, 8, 8};
198198
#endif
199199

@@ -258,14 +258,14 @@ static inline void skip_scan(scan_attr_t* scan_next_attr)
258258

259259
// User Privilege Flags
260260

261-
const int USER_PRIV_USER = 1;
262-
const int USER_PRIV_GRANTOR = 2;
263-
const int USER_PRIV_PRIVILEGE = 4;
264-
const int USER_PRIV_GRANT_OPTION = 8;
265-
const int USER_PRIV_OBJECT_NAME = 16;
266-
const int USER_PRIV_FIELD_NAME = 32;
267-
const int USER_PRIV_USER_TYPE = 64;
268-
const int USER_PRIV_OBJECT_TYPE = 128;
261+
constexpr int USER_PRIV_USER = 1;
262+
constexpr int USER_PRIV_GRANTOR = 2;
263+
constexpr int USER_PRIV_PRIVILEGE = 4;
264+
constexpr int USER_PRIV_GRANT_OPTION = 8;
265+
constexpr int USER_PRIV_OBJECT_NAME = 16;
266+
constexpr int USER_PRIV_FIELD_NAME = 32;
267+
constexpr int USER_PRIV_USER_TYPE = 64;
268+
constexpr int USER_PRIV_OBJECT_TYPE = 128;
269269

270270
static inline void collect_missing_privs(BurpGlobals* tdgbl, USHORT type, const QualifiedMetaString& name,
271271
bool hasSecClass)
@@ -361,7 +361,7 @@ int RESTORE_restore (const TEXT* file_name, const TEXT* database_name)
361361
// don't throw away the database just because an index
362362
// could not be made
363363
long error_code;
364-
while (error_code = tdgbl->status_vector[1])
364+
while ((error_code = tdgbl->status_vector[1]) != 0L)
365365
{
366366
switch (error_code)
367367
{
@@ -1564,7 +1564,7 @@ bool get_acl(BurpGlobals* tdgbl, const TEXT* owner_nm, ISC_QUAD* blob_id, ISC_QU
15641564
*
15651565
**************************************/
15661566

1567-
static const UCHAR blr_items[] =
1567+
static constexpr UCHAR blr_items[] =
15681568
{
15691569
isc_info_blob_max_segment,
15701570
isc_info_blob_total_length,
@@ -3193,7 +3193,7 @@ static void commit_relation_data(BurpGlobals* tdgbl, burp_rel* relation)
31933193
tdgbl->flag_on_line = false;
31943194

31953195
ISC_STATUS error_code;
3196-
while (error_code = tdgbl->status_vector[1])
3196+
while ((error_code = tdgbl->status_vector[1]) != 0)
31973197
{
31983198
Firebird::IRequest* req_handle = 0;
31993199
QualifiedMetaString indexName;
@@ -3276,7 +3276,7 @@ void fix_exception(BurpGlobals* tdgbl, const QualifiedMetaString& name, scan_att
32763276

32773277
// Notice we use 1021 instead of 1023 because this is the maximum length
32783278
// for this field in v2.0 and v2.1 and they produce the corrupt backups.
3279-
const unsigned int FIELD_LIMIT = 1021;
3279+
constexpr unsigned int FIELD_LIMIT = 1021;
32803280

32813281
if (FIELD_LIMIT < l2 + 1) // not enough space
32823282
{
@@ -6305,7 +6305,7 @@ bool get_global_field(BurpGlobals* tdgbl)
63056305
if (X.RDB$FIELD_TYPE <= DTYPE_BLR_MAX)
63066306
{
63076307
SSHORT l = gds_cvt_blr_dtype[X.RDB$FIELD_TYPE];
6308-
if (l = type_lengths[l])
6308+
if ((l = type_lengths[l]) != 0)
63096309
X.RDB$FIELD_LENGTH = l;
63106310
}
63116311

@@ -6651,7 +6651,7 @@ bool get_global_field(BurpGlobals* tdgbl)
66516651
if (X.RDB$FIELD_TYPE <= DTYPE_BLR_MAX)
66526652
{
66536653
SSHORT l = gds_cvt_blr_dtype[X.RDB$FIELD_TYPE];
6654-
if (l = type_lengths[l])
6654+
if ((l = type_lengths[l]) != 0)
66556655
X.RDB$FIELD_LENGTH = l;
66566656
}
66576657

@@ -8933,13 +8933,13 @@ bool get_mapping(BurpGlobals* tdgbl)
89338933
else
89348934
{
89358935
int match = 0;
8936-
const unsigned MATCH_FROM = 0x01;
8937-
const unsigned MATCH_FROM_TYPE = 0x02;
8938-
const unsigned MATCH_USING = 0x04;
8939-
const unsigned MATCH_PLUGIN = 0x08;
8940-
const unsigned MATCH_TO_TYPE = 0x10;
8941-
const unsigned MATCH_TO = 0x20;
8942-
const unsigned MATCH_ALL = 0x3f;
8936+
constexpr unsigned MATCH_FROM = 0x01;
8937+
constexpr unsigned MATCH_FROM_TYPE = 0x02;
8938+
constexpr unsigned MATCH_USING = 0x04;
8939+
constexpr unsigned MATCH_PLUGIN = 0x08;
8940+
constexpr unsigned MATCH_TO_TYPE = 0x10;
8941+
constexpr unsigned MATCH_TO = 0x20;
8942+
constexpr unsigned MATCH_ALL = 0x3f;
89438943
Firebird::NoCaseString txt;
89448944

89458945
skip_init(&scan_next_attr);
@@ -8994,6 +8994,8 @@ bool get_mapping(BurpGlobals* tdgbl)
89948994
match |= MATCH_TO;
89958995
break;
89968996

8997+
default:
8998+
break;
89978999
}
89989000
break;
89999001

@@ -12174,7 +12176,7 @@ void fix_generator(BurpGlobals* tdgbl, const FixGenerator* g)
1217412176
}
1217512177
}
1217612178

12177-
static const FixGenerator genToFix[] =
12179+
static constexpr FixGenerator genToFix[] =
1217812180
{
1217912181
{ "RDB$CONSTRAINT_NAME", "RDB$RELATION_CONSTRAINTS", "RDB$CONSTRAINT_NAME", "INTEG_" , DB_VERSION_DDL8 },
1218012182
{ "RDB$FIELD_NAME", "RDB$FIELDS", "RDB$FIELD_NAME", "RDB$" , DB_VERSION_DDL8 },
@@ -13242,7 +13244,7 @@ IBatch* WriteRelationMeta::createBatch(BurpGlobals* tdgbl, IAttachment* att)
1324213244
// determine batch parameters
1324313245
m_batchInlineBlobLimit = 0;
1324413246

13245-
const UCHAR items[] = {
13247+
constexpr UCHAR items[] = {
1324613248
IBatch::INF_BUFFER_BYTES_SIZE,
1324713249
IBatch::INF_BLOB_ALIGNMENT,
1324813250
IBatch::INF_BLOB_HEADER
@@ -13509,7 +13511,7 @@ void WriteRelationMeta::prepareRequest(BurpGlobals* tdgbl)
1350913511
{
1351013512
USHORT l = gds_cvt_blr_dtype[dtype];
1351113513
alignment = type_alignments[l];
13512-
if (l = type_lengths[l])
13514+
if ((l = type_lengths[l]) != 0)
1351313515
length = l;
1351413516
}
1351513517

@@ -14033,7 +14035,7 @@ IOBuffer* RestoreRelationTask::read_blob(BurpGlobals* tdgbl, IOBuffer* ioBuf)
1403314035
segments = value;
1403414036

1403514037
// for simplicity, don't split put attribute between buffers
14036-
const FB_SIZE_T attrLen = (sizeof(SLONG) + 2);
14038+
constexpr FB_SIZE_T attrLen = (sizeof(SLONG) + 2);
1403714039
checkSpace(&ioBuf, attrLen, &buf, &space);
1403814040

1403914041
*buf++ = attribute;

0 commit comments

Comments
 (0)