Skip to content

Commit 2a1f102

Browse files
authored
extended innovation in malloc to realloc and calloc (#6966)
1 parent 47c99cc commit 2a1f102

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/fread.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,8 +2036,8 @@ int freadMain(freadMainArgs _args) {
20362036
if (fill) INTERNAL_STOP("fill=true but there is a previous row which should already have been filled"); // # nocov
20372037
DTWARN(_("Detected %d column names but the data has %d columns. Filling rows automatically. Set fill=TRUE explicitly to avoid this warning.\n"), tt, ncol);
20382038
fill = true;
2039-
type = (int8_t *)realloc(type, (size_t)tt * sizeof(int8_t));
2040-
tmpType = (int8_t *)realloc(tmpType, (size_t)tt * sizeof(int8_t));
2039+
type = realloc(type, sizeof(*type) * tt);
2040+
tmpType = realloc(tmpType, sizeof(*tmpType) * tt);
20412041
if (!type || !tmpType) STOP(_("Failed to realloc 2 x %d bytes for type and tmpType: %s"), tt, strerror(errno));
20422042
for (int j=ncol; j<tt; j++) { tmpType[j] = type[j] = type0; }
20432043
ncol = tt;
@@ -2135,9 +2135,9 @@ int freadMain(freadMainArgs _args) {
21352135
if (args.header==false) {
21362136
colNames = NULL; // userOverride will assign V1, V2, etc
21372137
} else {
2138-
colNames = (lenOff*) calloc((size_t)ncol, sizeof(lenOff));
2138+
colNames = calloc(ncol, sizeof(*colNames));
21392139
if (!colNames)
2140-
STOP(_("Unable to allocate %d*%d bytes for column name pointers: %s"), ncol, sizeof(lenOff), strerror(errno)); // # nocov
2140+
STOP(_("Unable to allocate %d*%d bytes for column name pointers: %s"), ncol, sizeof(*colNames), strerror(errno)); // # nocov
21412141
if (sep==' ') while (*ch==' ') ch++;
21422142
void *targets[9] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, colNames + autoFirstColName};
21432143
FieldParseContext fctx = {
@@ -2516,9 +2516,9 @@ int freadMain(freadMainArgs _args) {
25162516
(int)(tch-fieldStart), fieldStart, (uint64_t)(ctx.DTi+myNrow));
25172517
if (len > 1000) len = 1000;
25182518
if (len > 0) {
2519-
typeBumpMsg = (char*) realloc(typeBumpMsg, typeBumpMsgSize + (size_t)len + 1);
2519+
typeBumpMsg = realloc(typeBumpMsg, typeBumpMsgSize + len + 1);
25202520
strcpy(typeBumpMsg+typeBumpMsgSize, temp);
2521-
typeBumpMsgSize += (size_t)len;
2521+
typeBumpMsgSize += len;
25222522
}
25232523
}
25242524
nTypeBump++;

0 commit comments

Comments
 (0)