Skip to content

Commit de5b963

Browse files
committed
implemented macro OffsetPointer
1 parent 73d79ed commit de5b963

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 OffsetPointer(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*)OffsetPointer(mmp_copy, fileSize);
453455
return wallclock()-tt;
454456
}
455457

@@ -2398,9 +2400,9 @@ int freadMain(freadMainArgs _args) {
23982400
break;
23992401
}
24002402
// shift current buffer positions, since `myBuffX`s were probably moved by realloc
2401-
fctx.targets[8] = (void*)((char*)ctx.buff8 + myNrow * rowSize8);
2402-
fctx.targets[4] = (void*)((char*)ctx.buff4 + myNrow * rowSize4);
2403-
fctx.targets[1] = (void*)((char*)ctx.buff1 + myNrow * rowSize1);
2403+
fctx.targets[8] = OffsetPointer(ctx.buff8, myNrow * rowSize8);
2404+
fctx.targets[4] = OffsetPointer(ctx.buff4, myNrow * rowSize4);
2405+
fctx.targets[1] = OffsetPointer(ctx.buff1, myNrow * rowSize1);
24042406
}
24052407
tLineStart = tch; // for error message
24062408
const char *fieldStart = tch;

0 commit comments

Comments
 (0)