Navigation Menu

Skip to content

Commit

Permalink
windows: use strcpy_s() on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 18, 2015
1 parent 5a7e2a9 commit aeb0bdc
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 48 deletions.
8 changes: 8 additions & 0 deletions include/groonga/portability.h
Expand Up @@ -93,6 +93,14 @@
strncat((dest), (src), (n))
#endif /* WIN32 */

#ifdef WIN32
# define grn_strcpy(dest, dest_size, src) \
strcpy_s((dest), (dest_size), (src))
#else /* WIN32 */
# define grn_strcpy(dest, dest_size, src) \
strcpy((dest), (src), (src))
#endif /* WIN32 */

#ifdef WIN32
# define grn_strncpy(dest, dest_size, src, n) \
strncpy_s((dest), (dest_size), (src), (n))
Expand Down
2 changes: 1 addition & 1 deletion lib/ctx.c
Expand Up @@ -606,7 +606,7 @@ grn_ctx_impl_set_current_error_message(grn_ctx *ctx)
}

grn_ctx_impl_clear_n_same_error_mssagges(ctx);
strcpy(ctx->impl->previous_errbuf, ctx->errbuf);
grn_strcpy(ctx->impl->previous_errbuf, GRN_CTX_MSGSIZE, ctx->errbuf);
}

static grn_rc
Expand Down
4 changes: 2 additions & 2 deletions lib/geo.c
Expand Up @@ -862,7 +862,7 @@ grn_geo_select_in_circle(grn_ctx *ctx, grn_obj *index,
name_size = grn_obj_name(ctx, domain_object, name, GRN_TABLE_MAX_KEY_SIZE);
grn_obj_unlink(ctx, domain_object);
} else {
strcpy(name, "(null)");
grn_strcpy(name, GRN_TABLE_MAX_KEY_SIZE, "(null)");
name_size = strlen(name);
}
ERR(GRN_INVALID_ARGUMENT,
Expand Down Expand Up @@ -1034,7 +1034,7 @@ in_rectangle_data_fill(grn_ctx *ctx, grn_obj *index,
name_size = grn_obj_name(ctx, domain_object, name, GRN_TABLE_MAX_KEY_SIZE);
grn_obj_unlink(ctx, domain_object);
} else {
strcpy(name, "(null)");
grn_strcpy(name, GRN_TABLE_MAX_KEY_SIZE, "(null)");
name_size = strlen(name);
}
ERR(GRN_INVALID_ARGUMENT,
Expand Down
4 changes: 2 additions & 2 deletions lib/ii.c
Expand Up @@ -3483,7 +3483,7 @@ _grn_ii_create(grn_ctx *ctx, grn_ii *ii, const char *path, grn_obj *lexicon, uin
S_SEGMENT, MAX_PSEG, grn_io_auto, GRN_IO_EXPIRE_SEGMENT);
if (!seg) { return NULL; }
if (path) {
strcpy(path2, path);
grn_strcpy(path2, PATH_MAX, path);
strcat(path2, ".c");
chunk = grn_io_create(ctx, path2, 0, S_CHUNK, GRN_II_MAX_CHUNK, grn_io_auto,
GRN_IO_EXPIRE_SEGMENT);
Expand Down Expand Up @@ -3602,7 +3602,7 @@ grn_ii_open(grn_ctx *ctx, const char *path, grn_obj *lexicon)
return NULL;
}
if (strlen(path) + 6 >= PATH_MAX) { return NULL; }
strcpy(path2, path);
grn_strcpy(path2, PATH_MAX, path);
strcat(path2, ".c");
seg = grn_io_open(ctx, path, grn_io_auto);
if (!seg) { return NULL; }
Expand Down
17 changes: 9 additions & 8 deletions lib/mrb.c
Expand Up @@ -49,7 +49,7 @@ grn_mrb_get_default_system_ruby_scripts_dir(void)

base_dir = grn_win32_base_dir();
base_dir_length = strlen(base_dir);
strcpy(win32_ruby_scripts_dir_buffer, base_dir);
grn_strcpy(win32_ruby_scripts_dir_buffer, PATH_MAX, base_dir);
strcat(win32_ruby_scripts_dir_buffer, "/");
strcat(win32_ruby_scripts_dir_buffer, relative_path);
win32_ruby_scripts_dir = win32_ruby_scripts_dir_buffer;
Expand Down Expand Up @@ -95,7 +95,8 @@ grn_mrb_is_absolute_path(const char *path)
}

static grn_bool
grn_mrb_expand_script_path(grn_ctx *ctx, const char *path, char *expanded_path)
grn_mrb_expand_script_path(grn_ctx *ctx, const char *path,
char *expanded_path, size_t expanded_path_size)
{
const char *ruby_scripts_dir;
char dir_last_char;
Expand All @@ -104,11 +105,11 @@ grn_mrb_expand_script_path(grn_ctx *ctx, const char *path, char *expanded_path)
if (grn_mrb_is_absolute_path(path)) {
expanded_path[0] = '\0';
} else if (path[0] == '.' && path[1] == '/') {
strcpy(expanded_path, ctx->impl->mrb.base_directory);
grn_strcpy(expanded_path, expanded_path_size, ctx->impl->mrb.base_directory);
strcat(expanded_path, "/");
} else {
ruby_scripts_dir = grn_mrb_get_system_ruby_scripts_dir(ctx);
strcpy(expanded_path, ruby_scripts_dir);
grn_strcpy(expanded_path, expanded_path_size, ruby_scripts_dir);

dir_last_char = ruby_scripts_dir[strlen(expanded_path) - 1];
if (dir_last_char != '/') {
Expand Down Expand Up @@ -145,7 +146,7 @@ grn_mrb_load(grn_ctx *ctx, const char *path)
return mrb_nil_value();
}

if (!grn_mrb_expand_script_path(ctx, path, expanded_path)) {
if (!grn_mrb_expand_script_path(ctx, path, expanded_path, PATH_MAX)) {
return mrb_nil_value();
}

Expand All @@ -166,8 +167,8 @@ grn_mrb_load(grn_ctx *ctx, const char *path)
char current_base_directory[PATH_MAX];
char *last_directory;

strcpy(current_base_directory, data->base_directory);
strcpy(data->base_directory, expanded_path);
grn_strcpy(current_base_directory, PATH_MAX, data->base_directory);
grn_strcpy(data->base_directory, PATH_MAX, expanded_path);
last_directory = strrchr(data->base_directory, '/');
if (last_directory) {
last_directory[0] = '\0';
Expand All @@ -187,7 +188,7 @@ grn_mrb_load(grn_ctx *ctx, const char *path)
}
mrb_parser_free(parser);

strcpy(data->base_directory, current_base_directory);
grn_strcpy(data->base_directory, PATH_MAX, current_base_directory);
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion lib/mrb/mrb_bulk.c
Expand Up @@ -148,7 +148,7 @@ grn_mrb_value_from_bulk(mrb_state *mrb, grn_obj *bulk)
domain_name, GRN_TABLE_MAX_KEY_SIZE);
grn_obj_unlink(ctx, domain);
} else {
strcpy(domain_name, "unknown");
grn_strcpy(domain_name, GRN_TABLE_MAX_KEY_SIZE, "unknown");
domain_name_size = strlen(domain_name);
}
snprintf(message, MESSAGE_SIZE,
Expand Down
8 changes: 4 additions & 4 deletions lib/plugin.c
Expand Up @@ -494,7 +494,7 @@ grn_plugin_get_default_system_plugins_dir(void)

base_dir = grn_win32_base_dir();
base_dir_length = strlen(base_dir);
strcpy(win32_plugins_dir_buffer, base_dir);
grn_strcpy(win32_plugins_dir_buffer, PATH_MAX, base_dir);
strcat(win32_plugins_dir_buffer, "/");
strcat(win32_plugins_dir_buffer, relative_path);
win32_plugins_dir = win32_plugins_dir_buffer;
Expand Down Expand Up @@ -562,7 +562,7 @@ grn_plugin_find_path_mrb(grn_ctx *ctx, const char *path, size_t path_len)
return NULL;
}

strcpy(mrb_path, path);
grn_strcpy(mrb_path, PATH_MAX, path);
strcat(mrb_path, mrb_suffix);
return grn_plugin_find_path_raw(ctx, mrb_path);
}
Expand Down Expand Up @@ -590,7 +590,7 @@ grn_plugin_find_path_so(grn_ctx *ctx, const char *path, size_t path_len)
return NULL;
}

strcpy(so_path, path);
grn_strcpy(so_path, PATH_MAX, path);
strcat(so_path, so_suffix);
return grn_plugin_find_path_raw(ctx, so_path);
}
Expand Down Expand Up @@ -645,7 +645,7 @@ grn_plugin_find_path(grn_ctx *ctx, const char *name)
path[0] = '\0';
} else {
plugins_dir = grn_plugin_get_system_plugins_dir();
strcpy(path, plugins_dir);
grn_strcpy(path, PATH_MAX, plugins_dir);

dir_last_char = plugins_dir[strlen(path) - 1];
if (dir_last_char != '/') {
Expand Down
2 changes: 1 addition & 1 deletion lib/proc.c
Expand Up @@ -2610,7 +2610,7 @@ proc_delete(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
GRN_EXPR_SYNTAX_SCRIPT);
if (ctx->rc) {
char original_error_message[GRN_CTX_MSGSIZE];
strcpy(original_error_message, ctx->errbuf);
grn_strcpy(original_error_message, GRN_CTX_MSGSIZE, ctx->errbuf);
rc = ctx->rc;
ERR(rc,
"[table][record][delete] failed to parse filter: "
Expand Down
16 changes: 8 additions & 8 deletions src/groonga.c
Expand Up @@ -142,7 +142,7 @@ line_editor_init(int argc __attribute__((unused)), char *argv[])
setlocale(LC_ALL, "");

if (strlen(HOME_PATH) + strlen(HISTORY_PATH) < PATH_MAX) {
strcpy(line_editor_history_path, HOME_PATH);
grn_strcpy(line_editor_history_path, PATH_MAX, HOME_PATH);
strcat(line_editor_history_path, HISTORY_PATH);
} else {
line_editor_history_path[0] = '\0';
Expand Down Expand Up @@ -2228,7 +2228,7 @@ config_file_register(const char *path, const grn_str_getopt_opt *opts,
char *args[4];

name_buf[0] = name_buf[1] = '-';
strcpy(name_buf + 2, name);
grn_strcpy(name_buf + 2, CONFIG_FILE_MAX_NAME_LENGTH + 1, name);

if (value) {
const size_t entry_size = sizeof(config_file_entry) + value_length + 1;
Expand All @@ -2238,7 +2238,7 @@ config_file_register(const char *path, const grn_str_getopt_opt *opts,
(unsigned int)entry_size);
return CONFIG_FILE_MALLOC_ERROR;
}
strcpy((char *)(entry + 1), value);
grn_strcpy((char *)(entry + 1), value_length + 1, value);
entry->next = config_file_entry_head;
if (!config_file_entry_head) {
if (atexit(config_file_clear)) {
Expand Down Expand Up @@ -2438,7 +2438,7 @@ init_default_settings(void)
if (document_root_length >= PATH_MAX) {
fprintf(stderr, "can't use default root: too long path\n");
} else {
strcpy(win32_default_document_root, grn_win32_base_dir());
grn_strcpy(win32_default_document_root, PATH_MAX, grn_win32_base_dir());
strcat(win32_default_document_root, "/");
strcat(win32_default_document_root, GRN_DEFAULT_RELATIVE_DOCUMENT_ROOT);
default_document_root = win32_default_document_root;
Expand Down Expand Up @@ -2998,9 +2998,9 @@ main(int argc, char **argv)
bind_address_arg, (unsigned int)bind_address_length, HOST_NAME_MAX);
return EXIT_FAILURE;
}
strcpy(bind_address, bind_address_arg);
grn_strcpy(bind_address, HOST_NAME_MAX + 1, bind_address_arg);
} else {
strcpy(bind_address, default_bind_address);
grn_strcpy(bind_address, HOST_NAME_MAX + 1, default_bind_address);
}

if (hostname_arg) {
Expand All @@ -3011,9 +3011,9 @@ main(int argc, char **argv)
hostname_arg, (unsigned int)hostname_length, HOST_NAME_MAX);
return EXIT_FAILURE;
}
strcpy(hostname, hostname_arg);
grn_strcpy(hostname, HOST_NAME_MAX + 1, hostname_arg);
} else {
strcpy(hostname, default_hostname);
grn_strcpy(hostname, HOST_NAME_MAX + 1, default_hostname);
}

if (document_root_arg) {
Expand Down

0 comments on commit aeb0bdc

Please sign in to comment.