1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

Cast the NULL argument of straconcat to unsigned char *.

straconcat reads the args with va_arg(ap, const unsigned char *),
and the NULL macro may have the wrong type (e.g. int).

Many places pass string literals of type char * to straconcat.  This
is in principle also a violation, but I'm ignoring it for now because
if it becomes a problem with some C implementation, then so will the
use of unsigned char * with printf "%s", which is so widespread in
ELinks that I'm not going to try fixing it now.
This commit is contained in:
Kalle Olavi Niemitalo 2007-03-11 12:59:11 +02:00 committed by Kalle Olavi Niemitalo
parent 22af2b22e2
commit 7645a836fc
30 changed files with 87 additions and 53 deletions

View File

@ -289,7 +289,8 @@ load_input_history(struct input_history *history, unsigned char *filename)
if (get_cmd_opt_bool("anonymous")) return 0;
if (elinks_home) {
history_file = straconcat(elinks_home, filename, NULL);
history_file = straconcat(elinks_home, filename,
(unsigned char *) NULL);
if (!history_file) return 0;
}
@ -327,7 +328,8 @@ save_input_history(struct input_history *history, unsigned char *filename)
|| get_cmd_opt_bool("anonymous"))
return 0;
history_file = straconcat(elinks_home, filename, NULL);
history_file = straconcat(elinks_home, filename,
(unsigned char *) NULL);
if (!history_file) return -1;
ssi = secure_open(history_file);

View File

@ -177,7 +177,7 @@ menu_labels(struct menu_item *items, unsigned char *base, unsigned char **lbls)
foreach_menu_item (item, items) {
bs = (item->flags & MENU_FULLNAME) ? (unsigned char *) ""
: base;
bs = straconcat(bs, item->text, NULL);
bs = straconcat(bs, item->text, (unsigned char *) NULL);
if (!bs) continue;
if (item->func == do_select_submenu) {

View File

@ -57,7 +57,8 @@ bookmarks_read(void)
file_name = backend->filename(0);
if (!file_name) return;
if (elinks_home) {
file_name = straconcat(elinks_home, file_name, NULL);
file_name = straconcat(elinks_home, file_name,
(unsigned char *) NULL);
if (!file_name) return;
}
@ -91,7 +92,7 @@ bookmarks_write(struct list_head *bookmarks_list)
* they would be just truncated to zero by secure_open()). */
file_name = backend->filename(1);
if (!file_name) return;
file_name = straconcat(elinks_home, file_name, NULL);
file_name = straconcat(elinks_home, file_name, (unsigned char *) NULL);
if (!file_name) return;
ssi = secure_open(file_name);

View File

@ -500,13 +500,15 @@ load_config_file(unsigned char *prefix, unsigned char *name,
{
unsigned char *config_str, *config_file;
config_file = straconcat(prefix, STRING_DIR_SEP, name, NULL);
config_file = straconcat(prefix, STRING_DIR_SEP, name,
(unsigned char *) NULL);
if (!config_file) return 1;
config_str = read_config_file(config_file);
if (!config_str) {
mem_free(config_file);
config_file = straconcat(prefix, STRING_DIR_SEP, ".", name, NULL);
config_file = straconcat(prefix, STRING_DIR_SEP, ".", name,
(unsigned char *) NULL);
if (!config_file) return 2;
config_str = read_config_file(config_file);
@ -802,7 +804,7 @@ write_config_file(unsigned char *prefix, unsigned char *name,
if (name_has_slash && prefix_has_slash) name++;
config_file = straconcat(prefix, slash, name, NULL);
config_file = straconcat(prefix, slash, name, (unsigned char *) NULL);
if (!config_file) goto free_cfg_str;
ssi = secure_open(config_file);

View File

@ -62,7 +62,8 @@ write_config_dialog(struct terminal *term, unsigned char *config_file,
strerr = secsave_strerror(secsave_error, term);
if (stdio_error > 0)
errmsg = straconcat(strerr, " (", strerror(stdio_error), ")", NULL);
errmsg = straconcat(strerr, " (", strerror(stdio_error), ")",
(unsigned char *) NULL);
info_box(term, MSGBOX_FREE_TEXT,
N_("Write config error"), ALIGN_CENTER,
@ -121,7 +122,8 @@ get_option_text(struct listbox_item *item, struct terminal *term)
if (option->flags & OPT_TOUCHED)
return straconcat(_(desc, term),
" (", _("modified", term), ")", NULL);
" (", _("modified", term), ")",
(unsigned char *) NULL);
return stracpy(_(desc, term));
}
@ -140,7 +142,8 @@ get_option_info(struct listbox_item *item, struct terminal *term)
type = _(option_types[option->type].name, term);
if (option->type == OPT_TREE) {
type = straconcat(type, " ",
_("(expand by pressing space)", term), NULL);
_("(expand by pressing space)", term),
(unsigned char *) NULL);
}
add_format_to_string(&info, "\n%s: %s", _("Type", term), type);
@ -325,17 +328,19 @@ build_edit_dialog(struct terminal *term, struct session *ses,
name = straconcat(_("Name", term), ": ", option->name, "\n",
_("Type", term), ": ",
_(option_types[option->type].name, term), NULL);
_(option_types[option->type].name, term),
(unsigned char *) NULL);
desc = straconcat(_("Description", term), ": \n",
_(option->desc ? option->desc
: (unsigned char *) "N/A", term),
NULL);
(unsigned char *) NULL);
range = get_range_string(option);
if (range) {
if (*range) {
unsigned char *tmp;
tmp = straconcat(name, " ", range, NULL);
tmp = straconcat(name, " ", range,
(unsigned char *) NULL);
if (tmp) {
mem_free(name);
name = tmp;

View File

@ -49,7 +49,8 @@ test_confdir(unsigned char *home, unsigned char *path,
if (!path || !*path) return NULL;
if (home && *home && !dir_sep(*path))
confdir = straconcat(home, STRING_DIR_SEP, path, NULL);
confdir = straconcat(home, STRING_DIR_SEP, path,
(unsigned char *) NULL);
else
confdir = stracpy(path);

View File

@ -940,7 +940,7 @@ bind_act(unsigned char *keymap_str, const unsigned char *keystroke_str)
return NULL;
keybinding->flags |= KBDB_WATERMARK;
return straconcat("\"", action, "\"", NULL);
return straconcat("\"", action, "\"", (unsigned char *) NULL);
}
static void

View File

@ -720,7 +720,8 @@ load_cookies(void) {
time_t now;
if (elinks_home) {
cookfile = straconcat(elinks_home, cookfile, NULL);
cookfile = straconcat(elinks_home, cookfile,
(unsigned char *) NULL);
if (!cookfile) return;
}
@ -861,7 +862,8 @@ save_cookies(struct terminal *term) {
return;
}
cookfile = straconcat(elinks_home, COOKIES_FILENAME, NULL);
cookfile = straconcat(elinks_home, COOKIES_FILENAME,
(unsigned char *) NULL);
if (!cookfile) {
CANNOT_SAVE_COOKIES(0, N_("Out of memory"));
return;

View File

@ -354,7 +354,8 @@ build_edit_dialog(struct terminal *term, struct cookie *cookie)
ulongcat(secure, &length, cookie->secure, MAX_STR_LEN, 0);
dlg_server = cookie->server->host;
dlg_server = straconcat(_("Server", term), ": ", dlg_server, "\n", NULL);
dlg_server = straconcat(_("Server", term), ": ", dlg_server, "\n",
(unsigned char *) NULL);
if (!dlg_server) {
mem_free(dlg);

View File

@ -152,7 +152,8 @@ get_current_link_info_and_title(struct session *ses,
if (link_title) {
assert(*link_title);
ret = straconcat(link_info, " - ", link_title, NULL);
ret = straconcat(link_info, " - ", link_title,
(unsigned char *) NULL);
mem_free(link_info);
mem_free(link_title);
}
@ -482,7 +483,8 @@ display_window_title(struct session *ses, struct terminal *term)
&& ses->doc_view->document->title[0])
doc_title = ses->doc_view->document->title;
title = doc_title ? straconcat(doc_title, " - ELinks", NULL)
title = doc_title ? straconcat(doc_title, " - ELinks",
(unsigned char *) NULL)
: stracpy("ELinks");
if (!title) return;

View File

@ -232,7 +232,8 @@ html_img_do(unsigned char *a, unsigned char *object_src,
mem_free(usemap_attr);
if (!joined_urls) return;
map_url = straconcat("MAP@", joined_urls, NULL);
map_url = straconcat("MAP@", joined_urls,
(unsigned char *) NULL);
mem_free(joined_urls);
if (!map_url) return;
@ -308,7 +309,7 @@ html_img_do(unsigned char *a, unsigned char *object_src,
if (img_link_tag && (img_link_tag == 2 || add_brackets)) {
unsigned char *img_link_prefix = options->image_link.prefix;
unsigned char *img_link_suffix = options->image_link.suffix;
unsigned char *new_label = straconcat(img_link_prefix, label, img_link_suffix, NULL);
unsigned char *new_label = straconcat(img_link_prefix, label, img_link_suffix, (unsigned char *) NULL);
if (new_label) mem_free_set(&label, new_label);
}
@ -327,7 +328,7 @@ html_img_do(unsigned char *a, unsigned char *object_src,
unsigned char *new_link;
html_stack_dup(html_context, ELEMENT_KILLABLE);
new_link = straconcat(format.link, "?0,0", NULL);
new_link = straconcat(format.link, "?0,0", (unsigned char *) NULL);
if (new_link)
mem_free_set(&format.link, new_link);
}

View File

@ -1409,7 +1409,8 @@ process_link(struct html_context *html_context, enum link_state link_state,
if (name) {
unsigned char *new_name;
new_name = straconcat(name, chars, NULL);
new_name = straconcat(name, chars,
(unsigned char *) NULL);
if (new_name) {
mem_free(name);
link->data.name = new_name;

View File

@ -123,7 +123,7 @@ check_link_word(struct document *document, unsigned char *uri, int length,
uri[length] = 0;
if (mailto && mailto > uri && mailto - uri < length - 1) {
where = straconcat("mailto:", uri, NULL);
where = straconcat("mailto:", uri, (unsigned char *) NULL);
} else if (parse_uri(&test, uri) == URI_ERRNO_OK
&& test.protocol != PROTOCOL_UNKNOWN

View File

@ -285,10 +285,10 @@ ecmascript_set_action(unsigned char **action, unsigned char *string)
struct uri *uri = get_uri(*action, URI_HTTP_REFERRER_HOST);
if (uri->protocol == PROTOCOL_FILE) {
mem_free_set(action, straconcat(struri(uri), string, NULL));
mem_free_set(action, straconcat(struri(uri), string, (unsigned char *) NULL));
}
else
mem_free_set(action, straconcat(struri(uri), string + 1, NULL));
mem_free_set(action, straconcat(struri(uri), string + 1, (unsigned char *) NULL));
done_uri(uri);
mem_free(string);
} else { /* relative uri */
@ -296,7 +296,8 @@ ecmascript_set_action(unsigned char **action, unsigned char *string)
unsigned char *new_action;
if (last_slash) *(last_slash + 1) = '\0';
new_action = straconcat(*action, string, NULL);
new_action = straconcat(*action, string,
(unsigned char *) NULL);
mem_free_set(action, new_action);
mem_free(string);
}

View File

@ -99,7 +99,8 @@ load_formhist_from_file(void)
if (!elinks_home) return 0;
file = straconcat(elinks_home, FORMS_HISTORY_FILENAME, NULL);
file = straconcat(elinks_home, FORMS_HISTORY_FILENAME,
(unsigned char *) NULL);
if (!file) return 0;
f = fopen(file, "rb");
@ -222,7 +223,8 @@ save_formhist_to_file(void)
if (!elinks_home || get_cmd_opt_bool("anonymous"))
return 0;
file = straconcat(elinks_home, FORMS_HISTORY_FILENAME, NULL);
file = straconcat(elinks_home, FORMS_HISTORY_FILENAME,
(unsigned char *) NULL);
if (!file) return 0;
ssi = secure_open(file);

View File

@ -341,7 +341,8 @@ read_global_history(void)
return;
if (elinks_home) {
file_name = straconcat(elinks_home, file_name, NULL);
file_name = straconcat(elinks_home, file_name,
(unsigned char *) NULL);
if (!file_name) return;
}
f = fopen(file_name, "rb");
@ -385,7 +386,8 @@ write_global_history(void)
|| get_cmd_opt_bool("anonymous"))
return;
file_name = straconcat(elinks_home, GLOBAL_HISTORY_FILENAME, NULL);
file_name = straconcat(elinks_home, GLOBAL_HISTORY_FILENAME,
(unsigned char *) NULL);
if (!file_name) return;
ssi = secure_open(file_name);

View File

@ -110,7 +110,8 @@ check_extension_type(unsigned char *extension)
if (!trimmed)
return NULL;
content_type = straconcat("application/x-", trimmed + 1, NULL);
content_type = straconcat("application/x-", trimmed + 1,
(unsigned char *) NULL);
if (!content_type)
return NULL;

View File

@ -86,7 +86,8 @@ open_new_window(struct terminal *term, unsigned char *exe_name,
if (twterm) command = twterm;
}
command = straconcat(command, " ", exe_name, " ", param, NULL);
command = straconcat(command, " ", exe_name, " ", param,
(unsigned char *) NULL);
if (!command) return;
exec_on_terminal(term, command, "", 2);

View File

@ -73,7 +73,8 @@ init_data_protocol_header(struct cache_entry *cached,
if (!type) return NULL;
/* Set fake content type */
head = straconcat("\r\nContent-Type: ", type, "\r\n", NULL);
head = straconcat("\r\nContent-Type: ", type, "\r\n",
(unsigned char *) NULL);
mem_free(type);
if (!head) return NULL;

View File

@ -112,7 +112,7 @@ add_dir_entry(struct directory_entry *entry, struct string *page,
if (readlen > 0 && readlen != MAX_STR_LEN) {
buf[readlen] = '\0';
lnk = straconcat(" -> ", buf, NULL);
lnk = straconcat(" -> ", buf, (unsigned char *) NULL);
}
if (!stat(entry->name, &st) && S_ISDIR(st.st_mode))

View File

@ -657,7 +657,7 @@ http_send_header(struct socket *socket)
if (user[0]) {
unsigned char *proxy_data;
proxy_data = straconcat(user, ":", passwd, NULL);
proxy_data = straconcat(user, ":", passwd, (unsigned char *) NULL);
if (proxy_data) {
unsigned char *proxy_64 = base64_encode(proxy_data);
@ -883,7 +883,8 @@ http_send_header(struct socket *socket)
unsigned char *id;
/* Create base64 encoded string. */
id = straconcat(entry->user, ":", entry->password, NULL);
id = straconcat(entry->user, ":", entry->password,
(unsigned char *) NULL);
if (id) {
unsigned char *base64 = base64_encode(id);

View File

@ -54,7 +54,8 @@ init_guile(struct module *module)
/* Remember the current module. */
user_module = scm_current_module();
path = straconcat(elinks_home, GUILE_HOOKS_FILENAME, NULL);
path = straconcat(elinks_home, GUILE_HOOKS_FILENAME,
(unsigned char *) NULL);
if (!path) return;
if (file_can_read(path)) {
@ -76,7 +77,8 @@ init_guile(struct module *module)
mem_free(path);
path = straconcat(elinks_home, GUILE_USERHOOKS_FILENAME, NULL);
path = straconcat(elinks_home, GUILE_USERHOOKS_FILENAME,
(unsigned char *) NULL);
if (!path) return;
if (file_can_read(path))
scm_c_primitive_load_path(path);

View File

@ -639,7 +639,8 @@ eval_function(LS, int num_args, int num_results)
static void
do_hooks_file(LS, unsigned char *prefix, unsigned char *filename)
{
unsigned char *file = straconcat(prefix, STRING_DIR_SEP, filename, NULL);
unsigned char *file = straconcat(prefix, STRING_DIR_SEP, filename,
(unsigned char *) NULL);
if (!file) return;

View File

@ -233,7 +233,8 @@ init_ruby(struct module *module)
init_erb_module();
if (elinks_home) {
path = straconcat(elinks_home, RUBY_HOOKS_FILENAME, NULL);
path = straconcat(elinks_home, RUBY_HOOKS_FILENAME,
(unsigned char *) NULL);
} else {
path = stracpy(CONFDIR STRING_DIR_SEP RUBY_HOOKS_FILENAME);

View File

@ -113,7 +113,8 @@ smjs_load_hooks(void)
assert(smjs_ctx);
if (elinks_home) {
path = straconcat(elinks_home, SMJS_HOOKS_FILENAME, NULL);
path = straconcat(elinks_home, SMJS_HOOKS_FILENAME,
(unsigned char *) NULL);
} else {
path = stracpy(CONFDIR STRING_DIR_SEP SMJS_HOOKS_FILENAME);
}

View File

@ -187,7 +187,7 @@ get_tempdir_filename(unsigned char *name)
if (!tmpdir || !*tmpdir) tmpdir = getenv("TEMP");
if (!tmpdir || !*tmpdir) tmpdir = "/tmp";
return straconcat(tmpdir, "/", name, NULL);
return straconcat(tmpdir, "/", name, (unsigned char *) NULL);
}
unsigned char *
@ -541,7 +541,8 @@ get_directory_entries(unsigned char *dirname, int get_hidden)
/* We allocate the full path because it is used in a few places
* which means less allocation although a bit more short term
* memory usage. */
name = straconcat(dirname, entry->d_name, NULL);
name = straconcat(dirname, entry->d_name,
(unsigned char *) NULL);
if (!name) continue;
if (!init_string(&attrib)) {

View File

@ -151,7 +151,8 @@ secure_open_umask(unsigned char *file_name)
*/
int fd;
unsigned char *randname = straconcat(ssi->file_name,
".tmp_XXXXXX", NULL);
".tmp_XXXXXX",
(unsigned char *) NULL);
if (!randname) {
secsave_errno = SS_ERR_OUT_OF_MEM;

View File

@ -50,11 +50,11 @@ void add_to_strn(unsigned char **str, const unsigned char *src);
unsigned char *insert_in_string(unsigned char **dst, int pos,
const unsigned char *seq, int seqlen);
/* Takes a list of strings where the last parameter _must_ be NULL and
* concatenates them. */
/* Takes a list of strings where the last parameter _must_ be
* (unsigned char *) NULL and concatenates them. */
/* Returns the allocated string or NULL on allocation failure. */
/* Example:
* unsigned char *abc = straconcat("A", "B", "C", NULL);
* unsigned char *abc = straconcat("A", "B", "C", (unsigned char *) NULL);
* if (abc) return;
* printf("%s", abc); -> print "ABC"
* mem_free(abc); -> free memory used by @abc */

View File

@ -659,13 +659,13 @@ add_submitted_value_to_list(struct form_control *fc,
break;
case FC_IMAGE:
name = straconcat(fc->name, ".x", NULL);
name = straconcat(fc->name, ".x", (unsigned char *) NULL);
if (!name) break;
sub = init_submitted_value(name, "0", type, fc, position);
mem_free(name);
if (sub) add_to_list(*list, sub);
name = straconcat(fc->name, ".y", NULL);
name = straconcat(fc->name, ".y", (unsigned char *) NULL);
if (!name) break;
sub = init_submitted_value(name, "0", type, fc, position);
mem_free(name);

View File

@ -611,7 +611,7 @@ textarea_edit(int op, struct terminal *term_, struct form_state *fs_,
if (!ed || !*ed) ed = "vi";
}
ex = straconcat(ed, " ", fn, NULL);
ex = straconcat(ed, " ", fn, (unsigned char *) NULL);
if (!ex) {
unlink(fn);
goto free_and_return;