summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2010-06-09 08:15:07 +0200
committerJim Meyering <meyering@redhat.com>2011-01-30 20:44:11 +0100
commita40a8fe1e52a78dc9493cbcecc9a01e72f1a76d8 (patch)
tree07b9d0a181a7ceb75f3a52330b8cb5752a9a6607 /src
parent3058ffa5016bc11c1a46391ae0f6eb51643aad9e (diff)
downloadcoreutils-a40a8fe1e52a78dc9493cbcecc9a01e72f1a76d8.tar.xz
copy.c: ensure proper alignment of fiemap buffer
* src/copy.c (fiemap_copy): Ensure that our fiemap buffer is large enough and well-aligned. Replace "0LL" with equivalent "0" as 3rd argument to lseek.
Diffstat (limited to 'src')
-rw-r--r--src/copy.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/copy.c b/src/copy.c
index 6bb05068d..1d32913eb 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -170,11 +170,12 @@ fiemap_copy (int src_fd, int dest_fd, size_t buf_size,
char const *dst_name, bool *normal_copy_required)
{
bool last = false;
- char fiemap_buf[4096];
- struct fiemap *fiemap = (struct fiemap *) fiemap_buf;
+ union { struct fiemap f; char c[4096]; } fiemap_buf;
+ struct fiemap *fiemap = &fiemap_buf.f;
struct fiemap_extent *fm_ext = &fiemap->fm_extents[0];
- uint32_t count = ((sizeof fiemap_buf - sizeof (*fiemap))
- / sizeof (struct fiemap_extent));
+ enum { count = (sizeof fiemap_buf - sizeof *fiemap) / sizeof *fm_ext };
+ verify (count != 0);
+
off_t last_ext_logical = 0;
uint64_t last_ext_len = 0;
uint64_t last_read_size = 0;
@@ -184,7 +185,7 @@ fiemap_copy (int src_fd, int dest_fd, size_t buf_size,
/* This is required at least to initialize fiemap->fm_start,
but also serves (in mid 2010) to appease valgrind, which
appears not to know the semantics of the FIEMAP ioctl. */
- memset (fiemap_buf, 0, sizeof fiemap_buf);
+ memset (&fiemap_buf, 0, sizeof fiemap_buf);
do
{
@@ -219,13 +220,13 @@ fiemap_copy (int src_fd, int dest_fd, size_t buf_size,
off_t ext_logical = fm_ext[i].fe_logical;
uint64_t ext_len = fm_ext[i].fe_length;
- if (lseek (src_fd, ext_logical, SEEK_SET) < 0LL)
+ if (lseek (src_fd, ext_logical, SEEK_SET) < 0)
{
error (0, errno, _("cannot lseek %s"), quote (src_name));
return false;
}
- if (lseek (dest_fd, ext_logical, SEEK_SET) < 0LL)
+ if (lseek (dest_fd, ext_logical, SEEK_SET) < 0)
{
error (0, errno, _("cannot lseek %s"), quote (dst_name));
return false;