mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
get rid of strcpy
* addr2line.c (follow_debuglink): insert global_debug_dir by using memmove instead of copying to temporary buffer. * dln.c (dln_load): use memcpy with the known length instead of strcpy. * gc.c (rb_gc_unprotect_logging): use strdup instead of malloc and strcpy. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d0035dbdf8
commit
79c50a77ff
3 changed files with 17 additions and 13 deletions
23
addr2line.c
23
addr2line.c
|
@ -427,22 +427,25 @@ fill_lines(int num_traces, void **traces, int check_debuglink,
|
||||||
obj_info_t **objp, line_info_t *lines, int offset);
|
obj_info_t **objp, line_info_t *lines, int offset);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
append_obj(obj_info_t **objp) {
|
append_obj(obj_info_t **objp)
|
||||||
|
{
|
||||||
obj_info_t *newobj = calloc(1, sizeof(obj_info_t));
|
obj_info_t *newobj = calloc(1, sizeof(obj_info_t));
|
||||||
if (*objp) (*objp)->next = newobj;
|
if (*objp) (*objp)->next = newobj;
|
||||||
*objp = newobj;
|
*objp = newobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
follow_debuglink(char *debuglink, int num_traces, void **traces,
|
follow_debuglink(const char *debuglink, int num_traces, void **traces,
|
||||||
obj_info_t **objp, line_info_t *lines, int offset)
|
obj_info_t **objp, line_info_t *lines, int offset)
|
||||||
{
|
{
|
||||||
/* Ideally we should check 4 paths to follow gnu_debuglink,
|
/* Ideally we should check 4 paths to follow gnu_debuglink,
|
||||||
but we handle only one case for now as this format is used
|
but we handle only one case for now as this format is used
|
||||||
by some linux distributions. See GDB's info for detail. */
|
by some linux distributions. See GDB's info for detail. */
|
||||||
static const char global_debug_dir[] = "/usr/lib/debug";
|
static const char global_debug_dir[] = "/usr/lib/debug";
|
||||||
char *p, *subdir;
|
const size_t global_debug_dir_len = sizeof(global_debug_dir) - 1;
|
||||||
|
char *p;
|
||||||
obj_info_t *o1 = *objp, *o2;
|
obj_info_t *o1 = *objp, *o2;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
p = strrchr(binary_filename, '/');
|
p = strrchr(binary_filename, '/');
|
||||||
if (!p) {
|
if (!p) {
|
||||||
|
@ -450,11 +453,13 @@ follow_debuglink(char *debuglink, int num_traces, void **traces,
|
||||||
}
|
}
|
||||||
p[1] = '\0';
|
p[1] = '\0';
|
||||||
|
|
||||||
subdir = (char *)alloca(strlen(binary_filename) + 1);
|
len = strlen(binary_filename);
|
||||||
strcpy(subdir, binary_filename);
|
if (len >= PATH_MAX - global_debug_dir_len)
|
||||||
strcpy(binary_filename, global_debug_dir);
|
len = PATH_MAX - global_debug_dir_len - 1;
|
||||||
strlcat(binary_filename, subdir, PATH_MAX);
|
memmove(binary_filename + global_debug_dir_len, binary_filename, len);
|
||||||
strlcat(binary_filename, debuglink, PATH_MAX);
|
memcpy(binary_filename, global_debug_dir, global_debug_dir_len);
|
||||||
|
len += global_debug_dir_len;
|
||||||
|
strlcpy(binary_filename + len, debuglink, PATH_MAX - len);
|
||||||
|
|
||||||
append_obj(objp);
|
append_obj(objp);
|
||||||
o2 = *objp;
|
o2 = *objp;
|
||||||
|
@ -726,7 +731,7 @@ rb_dump_backtrace_with_lines(int num_traces, void **traces)
|
||||||
path = info.dli_fname;
|
path = info.dli_fname;
|
||||||
obj->path = path;
|
obj->path = path;
|
||||||
lines[i].path = path;
|
lines[i].path = path;
|
||||||
strcpy(binary_filename, path);
|
strlcpy(binary_filename, path, PATH_MAX);
|
||||||
if (fill_lines(num_traces, traces, 1, &obj, lines, i) == (uintptr_t)-1)
|
if (fill_lines(num_traces, traces, 1, &obj, lines, i) == (uintptr_t)-1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
4
dln.c
4
dln.c
|
@ -1250,7 +1250,6 @@ dln_load(const char *file)
|
||||||
#endif
|
#endif
|
||||||
#if !defined(_AIX) && !defined(NeXT)
|
#if !defined(_AIX) && !defined(NeXT)
|
||||||
const char *error = 0;
|
const char *error = 0;
|
||||||
#define DLN_ERROR() (error = dln_strerror(), strcpy(ALLOCA_N(char, strlen(error) + 1), error))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined _WIN32
|
#if defined _WIN32
|
||||||
|
@ -1349,7 +1348,8 @@ dln_load(const char *file)
|
||||||
|
|
||||||
init_fct = (void(*)())(VALUE)dlsym(handle, buf);
|
init_fct = (void(*)())(VALUE)dlsym(handle, buf);
|
||||||
if (init_fct == NULL) {
|
if (init_fct == NULL) {
|
||||||
error = DLN_ERROR();
|
const size_t errlen = strlen(error = dln_strerror()) + 1;
|
||||||
|
error = memcpy(ALLOCA_N(char, errlen), error, errlen);
|
||||||
dlclose(handle);
|
dlclose(handle);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
3
gc.c
3
gc.c
|
@ -6003,9 +6003,8 @@ rb_gc_unprotect_logging(void *objptr, const char *filename, int line)
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ptr = (char *)malloc(strlen(buff) + 1);
|
ptr = (strdup)(buff);
|
||||||
if (!ptr) rb_memerror();
|
if (!ptr) rb_memerror();
|
||||||
strcpy(ptr, buff);
|
|
||||||
}
|
}
|
||||||
st_insert(rgengc_unprotect_logging_table, (st_data_t)ptr, cnt);
|
st_insert(rgengc_unprotect_logging_table, (st_data_t)ptr, cnt);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue