From: Eric Bollengier Date: Mon, 7 Feb 2011 16:49:50 +0000 (+0100) Subject: Avoid extra strlen() in is_name_valid() X-Git-Tag: Release-7.0.0~1141 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7ea5b0f928c72b785005200d50c5f62016b1cb68;p=bacula%2Fbacula Avoid extra strlen() in is_name_valid() --- diff --git a/bacula/src/lib/edit.c b/bacula/src/lib/edit.c index d77d8bfaff..4192ece51e 100644 --- a/bacula/src/lib/edit.c +++ b/bacula/src/lib/edit.c @@ -466,13 +466,20 @@ bool is_an_integer(const char *n) * Check if the Volume name has legal characters * If ua is non-NULL send the message */ -bool is_name_valid(char *name, POOLMEM **msg) +bool is_name_valid(const char *name, POOLMEM **msg) { int len; - char *p; + const char *p; /* Special characters to accept */ const char *accept = ":.-_ "; + /* No name is invalid */ + if (!name) { + if (msg) { + Mmsg(msg, _("Empty name not allowed.\n")); + } + return false; + } /* Restrict the characters permitted in the Volume name */ for (p=name; *p; p++) { if (B_ISALPHA(*p) || B_ISDIGIT(*p) || strchr(accept, (int)(*p))) { @@ -483,7 +490,7 @@ bool is_name_valid(char *name, POOLMEM **msg) } return false; } - len = strlen(name); + len = p - name; if (len >= MAX_NAME_LENGTH) { if (msg) { Mmsg(msg, _("Name too long.\n")); diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 8a18b45908..42254795b4 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -190,7 +190,7 @@ char *edit_utime (utime_t val, char *buf, int buf_len); bool is_a_number (const char *num); bool is_a_number_list (const char *n); bool is_an_integer (const char *n); -bool is_name_valid (char *name, POOLMEM **msg); +bool is_name_valid (const char *name, POOLMEM **msg); /* jcr.c (most definitions are in src/jcr.h) */ void init_last_jobs_list();