Skip to content

Commit f032d66

Browse files
implemented macro OffsetPointer (#7012)
* implemented macro `OffsetPointer` * consistent naming style * simpler diff --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent 82e66e7 commit f032d66

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/fread.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ static void Field(FieldParseContext *ctx);
117117
#define IGNORE_BUMP(x) abs(x)
118118
#define TOGGLE_BUMP(x) (-x)
119119

120+
#define OFFSET_POINTER(x, offset) ((typeof(x))((char*)x + (offset)))
121+
120122
//=================================================================================================
121123
//
122124
// Utility functions
@@ -449,7 +451,7 @@ double copyFile(size_t fileSize) // only called in very very rare cases
449451
return -1.0; // # nocov
450452
memcpy(mmp_copy, mmp, fileSize);
451453
sof = mmp_copy;
452-
eof = (char *)mmp_copy + fileSize;
454+
eof = (char *)OFFSET_POINTER(mmp_copy, fileSize);
453455
return wallclock()-tt;
454456
}
455457

@@ -2406,9 +2408,9 @@ int freadMain(freadMainArgs _args) {
24062408
break;
24072409
}
24082410
// shift current buffer positions, since `myBuffX`s were probably moved by realloc
2409-
fctx.targets[8] = (void*)((char*)ctx.buff8 + myNrow * rowSize8);
2410-
fctx.targets[4] = (void*)((char*)ctx.buff4 + myNrow * rowSize4);
2411-
fctx.targets[1] = (void*)((char*)ctx.buff1 + myNrow * rowSize1);
2411+
fctx.targets[8] = OFFSET_POINTER(ctx.buff8, myNrow * rowSize8);
2412+
fctx.targets[4] = OFFSET_POINTER(ctx.buff4, myNrow * rowSize4);
2413+
fctx.targets[1] = OFFSET_POINTER(ctx.buff1, myNrow * rowSize1);
24122414
}
24132415
tLineStart = tch; // for error message
24142416
const char *fieldStart = tch;

0 commit comments

Comments
 (0)