Skip to content

Commit

Permalink
breg: remove default initializers from members of C-structs
Browse files Browse the repository at this point in the history
  • Loading branch information
franku authored and pstorz committed Mar 17, 2020
1 parent 6faee2b commit 39b2758
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 38 deletions.
4 changes: 2 additions & 2 deletions core/src/console/console.cc
Expand Up @@ -416,7 +416,7 @@ static void match_kw(regex_t* preg, const char* what, int len, POOLMEM*& buf)
{
int rc, size;
int nmatch = 20;
regmatch_t pmatch[20];
regmatch_t pmatch[20]{};

if (len <= 0) { return; }
rc = regexec(preg, what, nmatch, pmatch, 0);
Expand All @@ -436,7 +436,7 @@ static void match_kw(regex_t* preg, const char* what, int len, POOLMEM*& buf)
/* fill the items list with the output of the help command */
void GetArguments(const char* what)
{
regex_t preg;
regex_t preg{};
POOLMEM* buf;
int rc;
init_items();
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/dird.cc
Expand Up @@ -911,7 +911,7 @@ static void CleanUpOldFiles()
int len = strlen(me->working_directory);
POOLMEM* cleanup = GetPoolMemory(PM_MESSAGE);
POOLMEM* basename = GetPoolMemory(PM_MESSAGE);
regex_t preg1;
regex_t preg1{};
char prbuf[500];
BErrNo be;

Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/inc_conf.cc
Expand Up @@ -458,7 +458,7 @@ static void ScanIncludeOptions(LEX* lc, int keyword, char* opts, int optlen)
static void StoreRegex(LEX* lc, ResourceItem* item, int index, int pass)
{
int token, rc;
regex_t preg;
regex_t preg{};
char prbuf[500];
const char* type;
int newsize;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/migrate.cc
Expand Up @@ -681,7 +681,7 @@ static bool regex_find_jobids(JobControlRecord* jcr,
dlist* item_chain;
uitem* item = NULL;
uitem* last_item = NULL;
regex_t preg;
regex_t preg{};
char prbuf[500];
int rc;
bool ok = false;
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/ua_acl.cc
Expand Up @@ -89,10 +89,10 @@ static inline bool FindInAclList(alist* list,
int len)
{
int rc;
regex_t preg;
regex_t preg{};
int nmatch = 1;
bool retval = false;
regmatch_t pmatch[1];
regmatch_t pmatch[1]{};
const char* list_value;

/*
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ua_restore.cc
Expand Up @@ -1058,7 +1058,7 @@ static bool AskForFileregex(UaContext* ua, RestoreContext* rx)
if (ua->cmd[0] == '\0') {
break;
} else {
regex_t* fileregex_re = NULL;
regex_t* fileregex_re{};
int rc;
char errmsg[500] = "";

Expand Down
10 changes: 5 additions & 5 deletions core/src/lib/breg.h
Expand Up @@ -66,11 +66,11 @@ class BareosRegex {
void debug();

/* private */
POOLMEM* expr = nullptr; /**< search epression */
POOLMEM* subst = nullptr; /**< substitution */
regex_t preg = {}; /**< regex_t result of regcomp() */
regmatch_t regs[BREG_NREGS]; /**< contains match */
char* eor = nullptr; /**< end of regexp in expr */
POOLMEM* expr = nullptr; /**< search epression */
POOLMEM* subst = nullptr; /**< substitution */
regex_t preg{}; /**< regex_t result of regcomp() */
regmatch_t regs[BREG_NREGS]{}; /**< contains match */
char* eor = nullptr; /**< end of regexp in expr */

char* ReturnFname(const char* fname, int len); /**< return fname as result */
char* EditSubst(const char* fname, regmatch_t pmatch[]);
Expand Down
4 changes: 2 additions & 2 deletions core/src/lib/bregex.cc
Expand Up @@ -1354,7 +1354,7 @@ const char* re_compile_pattern(regex_t* bufp, unsigned char* regex)

int regcomp(regex_t* bufp, const char* regex, int cflags)
{
new (bufp) regex_t();
memset(bufp, 0, sizeof(regex_t));
bufp->cflags = cflags;
if (bufp->cflags & REG_ICASE) {
char *p, *lcase = strdup(regex);
Expand Down Expand Up @@ -1396,7 +1396,7 @@ int regexec(regex_t* preg,
{
int status;
int len = strlen(string);
struct re_registers regs;
re_registers regs{};

status = ReSearch(preg, (unsigned char*)string, len, 0, len, &regs);
if (status >= 0) { re_registers_to_regmatch(&regs, pmatch, nmatch); }
Expand Down
34 changes: 17 additions & 17 deletions core/src/lib/bregex.h
Expand Up @@ -79,8 +79,8 @@ extern "C" {
#define regoff_t int

typedef struct {
regoff_t rm_so = 0;
regoff_t rm_eo = 0;
regoff_t rm_so;
regoff_t rm_eo;
} regmatch_t;


Expand All @@ -94,26 +94,26 @@ typedef struct {

/* clang-format off */
struct regex_t {
unsigned char* buffer = nullptr; /* compiled pattern */
int allocated = 0; /* allocated size of compiled pattern */
int used = 0; /* actual length of compiled pattern */
unsigned char* fastmap = nullptr; /* fastmap[ch] is true if ch can start pattern */
unsigned char* translate = nullptr; /* translation to apply during compilation/matching */
unsigned char fastmap_accurate = 0; /* true if fastmap is valid */
unsigned char can_be_null = 0; /* true if can match empty string */
unsigned char uses_registers = 0; /* registers are used and need to be initialized */
int num_registers = 0; /* number of registers used */
unsigned char anchor = 0; /* anchor: 0=none 1=begline 2=begbuf */
char* errmsg = nullptr;
int cflags = 0; /* compilation flags */
POOLMEM* lcase = nullptr; /* used by REG_ICASE */
unsigned char* buffer; /* compiled pattern */
int allocated; /* allocated size of compiled pattern */
int used; /* actual length of compiled pattern */
unsigned char* fastmap; /* fastmap[ch] is true if ch can start pattern */
unsigned char* translate; /* translation to apply during compilation/matching */
unsigned char fastmap_accurate; /* true if fastmap is valid */
unsigned char can_be_null; /* true if can match empty string */
unsigned char uses_registers; /* registers are used and need to be initialized */
int num_registers; /* number of registers used */
unsigned char anchor; /* anchor: 0=none 1=begline 2=begbuf */
char* errmsg;
int cflags; /* compilation flags */
POOLMEM* lcase; /* used by REG_ICASE */
};
/* clang-format on */


typedef struct re_registers {
int start[RE_NREGS]{0}; /* start offset of region */
int end[RE_NREGS]{0}; /* end offset of region */
int start[RE_NREGS]; /* start offset of region */
int end[RE_NREGS]; /* end offset of region */
} * regexp_registers_t;

/* bit definitions for syntax */
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/bsys.cc
Expand Up @@ -53,7 +53,7 @@ static const char* secure_erase_cmdline = NULL;
int SaferUnlink(const char* pathname, const char* regx)
{
int rc;
regex_t preg1;
regex_t preg1{};
char prbuf[500];
int rtn;

Expand Down
3 changes: 2 additions & 1 deletion core/src/lib/parse_bsr.cc
Expand Up @@ -560,8 +560,9 @@ static storagedaemon::BootStrapRecord* store_fileregex(
if (bsr->fileregex) free(bsr->fileregex);
bsr->fileregex = strdup(lc->str);

if (bsr->fileregex_re == NULL)
if (bsr->fileregex_re == NULL) {
bsr->fileregex_re = (regex_t*)malloc(sizeof(regex_t));
}

rc = regcomp(bsr->fileregex_re, bsr->fileregex, REG_EXTENDED | REG_NOSUB);
if (rc != 0) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/lib/var.cc
Expand Up @@ -949,8 +949,8 @@ static int op_search_and_replace(var_t* var,
/* regular expression pattern based operation */
tokenbuf_t mydata;
tokenbuf_t myreplace;
regex_t preg;
regmatch_t pmatch[10];
regex_t preg{};
regmatch_t pmatch[10]{};
int regexec_flag;

/* copy pattern and data to own buffer to make sure they are EOS-terminated
Expand Down
2 changes: 1 addition & 1 deletion core/src/stored/stored.cc
Expand Up @@ -445,7 +445,7 @@ static void CleanUpOldFiles()
int len = strlen(me->working_directory);
POOLMEM* cleanup = GetPoolMemory(PM_MESSAGE);
POOLMEM* basename = GetPoolMemory(PM_MESSAGE);
regex_t preg1;
regex_t preg1{};
char prbuf[500];
BErrNo be;

Expand Down
2 changes: 1 addition & 1 deletion core/src/tools/bregex.cc
Expand Up @@ -55,7 +55,7 @@ static void usage()

int main(int argc, char* const* argv)
{
regex_t preg;
regex_t preg{};
char prbuf[500];
char* fname = NULL;
int rc, ch;
Expand Down

0 comments on commit 39b2758

Please sign in to comment.