Improve const char declarations

Declare C string constants using array syntax, avoid pointer syntax
when possible. They are different, the array syntax generates smaller,
faster code.

Also, const char[] should usually be static, again to avoid poor
compilation and runtime performance where compilers tend to
initialize the const declaration for every call instead of using
.rodata for the string.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
This commit is contained in:
Dimitri Papadopoulos
2021-12-08 22:37:51 +01:00
parent 78c26b6f21
commit a5d79fc230
5 changed files with 15 additions and 16 deletions

View File

@@ -20,7 +20,6 @@
#include <config.h>
#include <auth/common.h>
const char* pass_msg_second = "Please enter your challenge password.";
const char* pass_msg_failed = "Login failed.\nPlease enter your password.";
const char* pass_msg_otp = "Please enter your OTP password.";
const char pass_msg_second[] = "Please enter your challenge password.";
const char pass_msg_failed[] = "Login failed.\nPlease enter your password.";
const char pass_msg_otp[] = "Please enter your OTP password.";

View File

@@ -3,8 +3,8 @@
#define MAX_PASSWORD_TRIES 3
extern const char* pass_msg_second;
extern const char* pass_msg_otp;
extern const char* pass_msg_failed;
extern const char pass_msg_second[];
extern const char pass_msg_otp[];
extern const char pass_msg_failed[];
#endif

View File

@@ -89,8 +89,8 @@ void update_fd_limits(main_server_st * s, unsigned main)
void set_self_oom_score_adj(main_server_st * s)
{
#ifdef __linux__
const char proc_self_oom_adj_score_path[] = "/proc/self/oom_score_adj";
const char oom_adj_score_value[] = "1000";
static const char proc_self_oom_adj_score_path[] = "/proc/self/oom_score_adj";
static const char oom_adj_score_value[] = "1000";
size_t written = 0;
int fd;

View File

@@ -62,7 +62,7 @@ typedef enum script_type_t {
SCRIPT_DISCONNECT
} script_type_t;
static const char *type_name[] = {"up", "host-update", "down"};
static const char * const type_name[] = {"up", "host-update", "down"};
static void export_fw_info(main_server_st *s, struct proc_st* proc)
{