Skip to content

Commit 656140a

Browse files
committed
refactor: More flexible field copying macro
1 parent 5d334f6 commit 656140a

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/rifiuti-vista.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ _validate_index_file (const char *filename,
6262
goto validate_fail;
6363
}
6464

65-
copy_field (ver, VERSION_OFFSET, FILESIZE_OFFSET);
65+
copy_field (*ver, buf, VERSION_OFFSET, FILESIZE_OFFSET);
6666
*ver = GUINT64_FROM_LE (*ver);
6767
g_debug ("version = %" PRIu64, *ver);
6868

@@ -86,7 +86,7 @@ _validate_index_file (const char *filename,
8686

8787
// Version 2 adds a uint32 file name strlen before file name.
8888
// This presumably breaks the 260 char barrier in version 1.
89-
copy_field (&pathlen, VERSION1_FILENAME_OFFSET, VERSION2_FILENAME_OFFSET);
89+
copy_field (pathlen, buf, VERSION1_FILENAME_OFFSET, VERSION2_FILENAME_OFFSET);
9090
pathlen = GUINT32_FROM_LE (pathlen);
9191

9292
/* Header length + strlen in UTF-16 encoding */
@@ -163,8 +163,8 @@ _populate_record_data (void *buf,
163163
record = g_malloc0 (sizeof (rbin_struct));
164164
record->version = version;
165165

166-
memcpy (&record->filesize, buf + FILESIZE_OFFSET,
167-
FILETIME_OFFSET - FILESIZE_OFFSET - (int) erraneous);
166+
copy_field (record->filesize, buf, FILESIZE_OFFSET,
167+
FILETIME_OFFSET - (int) erraneous);
168168
if (erraneous)
169169
{
170170
g_debug ("filesize field broken, 56 bit only, val=0x%" PRIX64,
@@ -179,8 +179,8 @@ _populate_record_data (void *buf,
179179
}
180180

181181
/* File deletion time */
182-
memcpy (&record->winfiletime, buf - (int) erraneous + FILETIME_OFFSET,
183-
VERSION1_FILENAME_OFFSET - FILETIME_OFFSET);
182+
copy_field (record->winfiletime, buf - (int) erraneous,
183+
FILETIME_OFFSET, VERSION1_FILENAME_OFFSET);
184184
record->winfiletime = GINT64_FROM_LE (record->winfiletime);
185185
record->deltime = win_filetime_to_gdatetime (record->winfiletime);
186186

src/rifiuti.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ _validate_index_file (const char *filename,
6666
goto validation_fail;
6767
}
6868

69-
copy_field (&ver, VERSION_OFFSET, KEPT_ENTRY_OFFSET);
69+
copy_field (ver, buf, VERSION_OFFSET, KEPT_ENTRY_OFFSET);
7070
ver = GUINT32_FROM_LE (ver);
7171

7272
// total_entry only meaningful for 95 and NT4, on other versions
7373
// it's junk memory data, don't bother copying
7474
if ( ( ver == VERSION_NT4 ) || ( ver == VERSION_WIN95 ) ) {
75-
copy_field (&meta->total_entry, TOTAL_ENTRY_OFFSET, RECORD_SIZE_OFFSET);
75+
copy_field (meta->total_entry, buf, TOTAL_ENTRY_OFFSET, RECORD_SIZE_OFFSET);
7676
meta->total_entry = GUINT32_FROM_LE (meta->total_entry);
7777
}
7878

79-
copy_field (&meta->recordsize, RECORD_SIZE_OFFSET, FILESIZE_SUM_OFFSET);
79+
copy_field (meta->recordsize, buf, RECORD_SIZE_OFFSET, FILESIZE_SUM_OFFSET);
8080
meta->recordsize = GUINT32_FROM_LE (meta->recordsize);
8181

8282
g_free (buf);
@@ -150,15 +150,16 @@ _populate_record_data (void *buf,
150150

151151
// Verbatim path in ANSI code page
152152
record->raw_legacy_path = g_malloc0 (RECORD_INDEX_OFFSET - LEGACY_FILENAME_OFFSET);
153-
copy_field (record->raw_legacy_path, LEGACY_FILENAME_OFFSET, RECORD_INDEX_OFFSET);
153+
copy_field (*(record->raw_legacy_path), buf,
154+
LEGACY_FILENAME_OFFSET, RECORD_INDEX_OFFSET);
154155

155156
/* Index number associated with the record */
156-
copy_field (&record->index_n, RECORD_INDEX_OFFSET, DRIVE_LETTER_OFFSET);
157+
copy_field (record->index_n, buf, RECORD_INDEX_OFFSET, DRIVE_LETTER_OFFSET);
157158
record->index_n = GUINT32_FROM_LE (record->index_n);
158159
g_debug ("index=%u", record->index_n);
159160

160161
/* Number representing drive letter, 'A:' = 0, etc */
161-
copy_field (&drivenum, DRIVE_LETTER_OFFSET, FILETIME_OFFSET);
162+
copy_field (drivenum, buf, DRIVE_LETTER_OFFSET, FILETIME_OFFSET);
162163
drivenum = GUINT32_FROM_LE (drivenum);
163164
g_debug ("drive=%u", drivenum);
164165
if (drivenum >= sizeof (driveletters) - 1) {
@@ -179,13 +180,14 @@ _populate_record_data (void *buf,
179180
}
180181

181182
/* File deletion time */
182-
copy_field (&record->winfiletime, FILETIME_OFFSET, FILESIZE_OFFSET);
183+
copy_field (record->winfiletime, buf, FILETIME_OFFSET, FILESIZE_OFFSET);
183184
record->winfiletime = GINT64_FROM_LE (record->winfiletime);
184185
record->deltime = win_filetime_to_gdatetime (record->winfiletime);
185186

186187
/* File size or occupied cluster size */
187188
/* BEWARE! This is 32bit data casted to 64bit struct member */
188-
copy_field (&record->filesize, FILESIZE_OFFSET, UNICODE_FILENAME_OFFSET);
189+
copy_field (record->filesize, buf,
190+
FILESIZE_OFFSET, UNICODE_FILENAME_OFFSET);
189191
record->filesize = GUINT64_FROM_LE (record->filesize);
190192
g_debug ("filesize=%" PRIu64, record->filesize);
191193

@@ -210,7 +212,8 @@ _populate_record_data (void *buf,
210212

211213
uni_buf_sz = UNICODE_RECORD_SIZE - UNICODE_FILENAME_OFFSET;
212214
record->raw_uni_path = g_malloc (uni_buf_sz);
213-
copy_field (record->raw_uni_path, UNICODE_FILENAME_OFFSET, UNICODE_RECORD_SIZE);
215+
copy_field (*(record->raw_uni_path), buf,
216+
UNICODE_FILENAME_OFFSET, UNICODE_RECORD_SIZE);
214217
null_terminator_offset = ucs2_strnlen (
215218
record->raw_uni_path, WIN_PATH_MAX) * sizeof (gunichar2);
216219

src/utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ typedef struct _rbin_struct
212212
} rbin_struct;
213213

214214
/* convenience macro */
215-
#define copy_field(field, off1, off2) \
216-
memcpy((field), buf + (off1), (off2) - (off1))
215+
#define copy_field(field, buf, off1, off2) \
216+
memcpy(&(field), (buf) + (off1), (off2) - (off1))
217217

218218
/*! Every Windows use this GUID in recycle bin desktop.ini */
219219
#define RECYCLE_BIN_CLSID "645FF040-5081-101B-9F08-00AA002F954E"

0 commit comments

Comments
 (0)