Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] u_char to char conversion #1400

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions auto/cc/test
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ case $NXT_CC_NAME in

NXT_CFLAGS="$NXT_CFLAGS -fno-strict-overflow"

NXT_CFLAGS="$NXT_CFLAGS -funsigned-char"

NXT_CFLAGS="$NXT_CFLAGS -std=gnu11"

NXT_CFLAGS="$NXT_CFLAGS -O"
Expand All @@ -77,6 +79,9 @@ case $NXT_CC_NAME in
#NXT_CFLAGS="$NXT_CFLAGS -Wshorten-64-to-32"
NXT_CFLAGS="$NXT_CFLAGS -Wwrite-strings"

# OK due to -funsigned-char
NXT_CFLAGS="$NXT_CFLAGS -Wno-char-subscripts"

# -O2 enables -fstrict-aliasing and -fstrict-overflow.
#NXT_CFLAGS="$NXT_CFLAGS -O2"
NXT_CFLAGS="$NXT_CFLAGS -fno-strict-aliasing"
Expand Down Expand Up @@ -109,6 +114,8 @@ case $NXT_CC_NAME in

NXT_CFLAGS="$NXT_CFLAGS -fno-strict-overflow"

NXT_CFLAGS="$NXT_CFLAGS -funsigned-char"

NXT_CFLAGS="$NXT_CFLAGS -std=gnu11"

NXT_CFLAGS="$NXT_CFLAGS -O"
Expand All @@ -122,6 +129,9 @@ case $NXT_CC_NAME in
# strict-aliasing is always enabled by default in clang
NXT_CFLAGS="$NXT_CFLAGS -fno-strict-aliasing"

# OK due to -funsigned-char
NXT_CFLAGS="$NXT_CFLAGS -Wno-char-subscripts"

#NXT_CFLAGS="$NXT_CFLAGS -fomit-frame-pointer"
NXT_CFLAGS="$NXT_CFLAGS -Wstrict-overflow=5"

Expand Down
18 changes: 9 additions & 9 deletions src/nxt_app_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@


static nxt_time_string_t nxt_log_error_time_cache;
static u_char *nxt_log_error_time(u_char *buf, nxt_realtime_t *now,
static char *nxt_log_error_time(char *buf, nxt_realtime_t *now,
struct tm *tm, size_t size, const char *format);
static nxt_time_string_t nxt_log_debug_time_cache;
static u_char *nxt_log_debug_time(u_char *buf, nxt_realtime_t *now,
static char *nxt_log_debug_time(char *buf, nxt_realtime_t *now,
struct tm *tm, size_t size, const char *format);


void nxt_cdecl
nxt_log_time_handler(nxt_uint_t level, nxt_log_t *log, const char *fmt, ...)
{
u_char *p, *end;
char *p, *end;
#if 0
u_char *syslogmsg;
char *syslogmsg;
#endif
va_list args;
nxt_thread_t *thr;
nxt_time_string_t *time_cache;
u_char msg[NXT_MAX_ERROR_STR];
char msg[NXT_MAX_ERROR_STR];

thr = nxt_thread();

Expand Down Expand Up @@ -108,8 +108,8 @@ static nxt_time_string_t nxt_log_error_time_cache = {
};


static u_char *
nxt_log_error_time(u_char *buf, nxt_realtime_t *now, struct tm *tm, size_t size,
static char *
nxt_log_error_time(char *buf, nxt_realtime_t *now, struct tm *tm, size_t size,
const char *format)
{
return nxt_sprintf(buf, buf + size, format,
Expand All @@ -128,8 +128,8 @@ static nxt_time_string_t nxt_log_debug_time_cache = {
};


static u_char *
nxt_log_debug_time(u_char *buf, nxt_realtime_t *now, struct tm *tm, size_t size,
static char *
nxt_log_debug_time(char *buf, nxt_realtime_t *now, struct tm *tm, size_t size,
const char *format)
{
return nxt_sprintf(buf, buf + size, format,
Expand Down
28 changes: 14 additions & 14 deletions src/nxt_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void nxt_proto_quit_children(nxt_task_t *task);
static nxt_process_t *nxt_proto_process_find(nxt_task_t *task, nxt_pid_t pid);
static void nxt_proto_process_add(nxt_task_t *task, nxt_process_t *process);
static nxt_process_t *nxt_proto_process_remove(nxt_task_t *task, nxt_pid_t pid);
static u_char *nxt_cstr_dup(nxt_mp_t *mp, u_char *dst, u_char *src);
static char *nxt_cstr_dup(nxt_mp_t *mp, char *dst, char *src);
static void nxt_proto_signal_handler(nxt_task_t *task, void *obj, void *data);
static void nxt_proto_sigterm_handler(nxt_task_t *task, void *obj, void *data);
static void nxt_proto_sigchld_handler(nxt_task_t *task, void *obj, void *data);
Expand Down Expand Up @@ -207,7 +207,7 @@ static nxt_buf_t *
nxt_discovery_modules(nxt_task_t *task, const char *path)
{
char *name;
u_char *p, *end;
char *p, *end;
size_t size;
glob_t glb;
nxt_mp_t *mp;
Expand Down Expand Up @@ -310,7 +310,7 @@ nxt_discovery_modules(nxt_task_t *task, const char *path)
"\"data\": \"%s\"},",
mnt[j].src, mnt[j].dst, mnt[j].name, mnt[j].type,
mnt[j].flags,
mnt[j].data == NULL ? (u_char *) "" : mnt[j].data);
mnt[j].data == NULL ? (char *) "" : mnt[j].data);
}

*p++ = ']';
Expand Down Expand Up @@ -388,7 +388,7 @@ nxt_discovery_module(nxt_task_t *task, nxt_mp_t *mp, nxt_array_t *modules,
module = modules->elts;
n = modules->nelts;

version.start = (u_char *) app->version;
version.start = (char *) app->version;
version.length = nxt_strlen(app->version);

for (i = 0; i < n; i++) {
Expand Down Expand Up @@ -603,7 +603,7 @@ nxt_proto_start(nxt_task_t *task, nxt_process_data_t *data)
static void
nxt_proto_start_process_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
{
u_char *p;
char *p;
nxt_int_t ret;
nxt_port_t *port;
nxt_runtime_t *rt;
Expand Down Expand Up @@ -641,7 +641,7 @@ nxt_proto_start_process_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)

init->name = (const char *) nxt_app_conf->name.start;

p = (u_char *) process->name;
p = (char *) process->name;
*p++ = '"';
p = nxt_cpymem(p, nxt_app_conf->name.start, nxt_app_conf->name.length);
p = nxt_cpymem(p, "\" application", 13);
Expand Down Expand Up @@ -968,7 +968,7 @@ nxt_app_set_logs(void)
if (app_conf->stdout_log != NULL) {
nxt_memzero(&file, sizeof(nxt_file_t));
file.log_level = 1;
file.name = (u_char *) app_conf->stdout_log;
file.name = (char *) app_conf->stdout_log;
ret = nxt_file_open(task, &file, O_WRONLY | O_APPEND, O_CREAT, 0666);
if (ret == NXT_ERROR) {
return NXT_ERROR;
Expand All @@ -981,7 +981,7 @@ nxt_app_set_logs(void)
if (app_conf->stderr_log != NULL) {
nxt_memzero(&file, sizeof(nxt_file_t));
file.log_level = 1;
file.name = (u_char *) app_conf->stderr_log;
file.name = (char *) app_conf->stderr_log;
ret = nxt_file_open(task, &file, O_WRONLY | O_APPEND, O_CREAT, 0666);
if (ret == NXT_ERROR) {
return NXT_ERROR;
Expand All @@ -995,10 +995,10 @@ nxt_app_set_logs(void)
}


static u_char *
nxt_cstr_dup(nxt_mp_t *mp, u_char *dst, u_char *src)
static char *
nxt_cstr_dup(nxt_mp_t *mp, char *dst, char *src)
{
u_char *p;
char *p;
size_t len;

len = nxt_strlen(src);
Expand Down Expand Up @@ -1033,7 +1033,7 @@ nxt_app_setup(nxt_task_t *task, nxt_process_t *process)
nxt_app_lang_module_t *
nxt_app_lang_module(nxt_runtime_t *rt, nxt_str_t *name)
{
u_char *p, *end, *version;
char *p, *end, *version;
size_t version_length;
nxt_uint_t i, n;
nxt_app_type_t type;
Expand Down Expand Up @@ -1084,7 +1084,7 @@ nxt_app_lang_module(nxt_runtime_t *rt, nxt_str_t *name)


nxt_app_type_t
nxt_app_parse_type(u_char *p, size_t length)
nxt_app_parse_type(char *p, size_t length)
{
nxt_str_t str;

Expand Down Expand Up @@ -1205,7 +1205,7 @@ nxt_proto_process_lhq_pid(nxt_lvlhsh_query_t *lhq, nxt_pid_t *pid)
{
lhq->key_hash = nxt_murmur_hash2(pid, sizeof(nxt_pid_t));
lhq->key.length = sizeof(nxt_pid_t);
lhq->key.start = (u_char *) pid;
lhq->key.start = (char *) pid;
lhq->proto = &lvlhsh_processes_proto;
}

Expand Down
4 changes: 2 additions & 2 deletions src/nxt_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef nxt_int_t (*nxt_application_setup_t)(nxt_task_t *task,
typedef struct {
nxt_app_type_t type;
char *name;
u_char *version;
char *version;
char *file;
nxt_app_module_t *module;
nxt_array_t *mounts; /* of nxt_fs_mount_t */
Expand Down Expand Up @@ -165,7 +165,7 @@ struct nxt_app_module_s {


nxt_app_lang_module_t *nxt_app_lang_module(nxt_runtime_t *rt, nxt_str_t *name);
nxt_app_type_t nxt_app_parse_type(u_char *p, size_t length);
nxt_app_type_t nxt_app_parse_type(char *p, size_t length);

NXT_EXPORT extern nxt_str_t nxt_server;
extern nxt_app_module_t nxt_external_module;
Expand Down
8 changes: 4 additions & 4 deletions src/nxt_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
*/

typedef struct {
u_char *pos;
u_char *free;
u_char *start;
u_char *end;
char *pos;
char *free;
char *start;
char *end;
} nxt_buf_mem_t;


Expand Down
20 changes: 10 additions & 10 deletions src/nxt_cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ nxt_cert_bio(nxt_task_t *task, BIO *bio)
EVP_PKEY *key;
nxt_uint_t nalloc;
nxt_cert_t *cert, *new_cert;
u_char *data;
const u_char *data_copy;
char *data;
const char *data_copy;
PKCS8_PRIV_KEY_INFO *p8inf;
const EVP_PKEY_ASN1_METHOD *ameth;

Expand Down Expand Up @@ -493,14 +493,14 @@ nxt_cert_details(nxt_mp_t *mp, nxt_cert_t *cert)
{
BIO *bio;
X509 *x509;
u_char *end;
char *end;
EVP_PKEY *key;
ASN1_TIME *asn1_time;
nxt_str_t str;
nxt_int_t ret;
nxt_uint_t i;
nxt_conf_value_t *object, *chain, *element, *value;
u_char buf[256];
char buf[256];

static nxt_str_t key_str = nxt_string("key");
static nxt_str_t chain_str = nxt_string("chain");
Expand Down Expand Up @@ -658,7 +658,7 @@ nxt_cert_name_details(nxt_mp_t *mp, X509 *x509, nxt_bool_t issuer)
nxt_uint_t i, n, count;
nxt_conf_value_t *object, *names;
STACK_OF(GENERAL_NAME) *alt_names;
u_char buf[256];
char buf[256];

static nxt_cert_nid_t nids[] = {
{ NID_commonName, nxt_string("common_name") },
Expand Down Expand Up @@ -772,7 +772,7 @@ nxt_cert_alt_names_details(nxt_mp_t *mp, STACK_OF(GENERAL_NAME) *alt_names)

str.length = ASN1_STRING_length(name->d.dNSName);
#if OPENSSL_VERSION_NUMBER > 0x10100000L
str.start = (u_char *) ASN1_STRING_get0_data(name->d.dNSName);
str.start = (char *) ASN1_STRING_get0_data(name->d.dNSName);
#else
str.start = ASN1_STRING_data(name->d.dNSName);
#endif
Expand Down Expand Up @@ -815,7 +815,7 @@ nxt_cert_store_load(nxt_task_t *task, nxt_mp_t *mp)
{
DIR *dir;
size_t size, alloc;
u_char *buf, *p;
char *buf, *p;
nxt_str_t name;
nxt_int_t ret;
nxt_file_t file;
Expand Down Expand Up @@ -855,7 +855,7 @@ nxt_cert_store_load(nxt_task_t *task, nxt_mp_t *mp)
nxt_debug(task, "readdir(\"%s\"): \"%s\"", rt->certs.start, de->d_name);

name.length = nxt_strlen(de->d_name);
name.start = (u_char *) de->d_name;
name.start = (char *) de->d_name;

if (nxt_str_eq(&name, ".", 1) || nxt_str_eq(&name, "..", 2)) {
continue;
Expand Down Expand Up @@ -1123,7 +1123,7 @@ nxt_cert_buf_completion(nxt_task_t *task, void *obj, void *data)
void
nxt_cert_store_get_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
{
u_char *p;
char *p;
nxt_int_t ret;
nxt_str_t name;
nxt_file_t file;
Expand Down Expand Up @@ -1213,7 +1213,7 @@ nxt_cert_store_delete(nxt_task_t *task, nxt_str_t *name, nxt_mp_t *mp)
void
nxt_cert_store_delete_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
{
u_char *p;
char *p;
nxt_str_t name;
nxt_port_t *ctl_port;
nxt_runtime_t *rt;
Expand Down
2 changes: 1 addition & 1 deletion src/nxt_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ nxt_cgroup_proc_add(nxt_task_t *task, nxt_process_t *process)
return NXT_ERROR;
}

ret = nxt_fs_mkdir_p((const u_char *) cgprocs, 0777);
ret = nxt_fs_mkdir_p((const char *) cgprocs, 0777);
if (nxt_slow_path(ret == NXT_ERROR)) {
return NXT_ERROR;
}
Expand Down
8 changes: 4 additions & 4 deletions src/nxt_clang.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ nxt_popcount(unsigned int x)


#define nxt_container_of(p, type, field) \
(type *) ((u_char *) (p) - offsetof(type, field))
(type *) ((char *) (p) - offsetof(type, field))


#define nxt_pointer_to(p, offset) \
((void *) ((char *) (p) + (offset)))


#define nxt_value_at(type, p, offset) \
*(type *) ((u_char *) p + offset)
*(type *) ((char *) p + offset)


#define nxt_nitems(x) \
Expand Down Expand Up @@ -244,11 +244,11 @@ nxt_popcount(unsigned int x)


#define nxt_align_ptr(p, a) \
(u_char *) (((uintptr_t) (p) + ((uintptr_t) (a) - 1)) \
(char *) (((uintptr_t) (p) + ((uintptr_t) (a) - 1)) \
& ~((uintptr_t) (a) - 1))

#define nxt_trunc_ptr(p, a) \
(u_char *) ((uintptr_t) (p) & ~((uintptr_t) (a) - 1))
(char *) ((uintptr_t) (p) & ~((uintptr_t) (a) - 1))


#define nxt_length(s) \
Expand Down
Loading
Loading