summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d95457e)
* src/compare.c (diff_symlink):
Don't use alloca on symlink length; it might be too big for the stack.
Don't assume that readlinkat's return value fits in 'int'.
Prefer memcmp to strncmp where either will do.
static void
diff_symlink (void)
{
static void
diff_symlink (void)
{
size_t len = strlen (current_stat_info.link_name);
size_t len = strlen (current_stat_info.link_name);
- char *linkbuf = alloca (len + 1);
+ char *linkbuf = len < sizeof buf ? buf : xmalloc (len + 1);
- int status = readlinkat (chdir_fd, current_stat_info.file_name,
- linkbuf, len + 1);
+ ssize_t status = readlinkat (chdir_fd, current_stat_info.file_name,
+ linkbuf, len + 1);
report_difference (¤t_stat_info, NULL);
}
else if (status != len
report_difference (¤t_stat_info, NULL);
}
else if (status != len
- || strncmp (current_stat_info.link_name, linkbuf, len) != 0)
+ || memcmp (current_stat_info.link_name, linkbuf, len) != 0)
report_difference (¤t_stat_info, _("Symlink differs"));
report_difference (¤t_stat_info, _("Symlink differs"));
+
+ if (linkbuf != buf)
+ free (linkbuf);