Skip to content

Commit fb4e807

Browse files
committed
extended innovation in malloc to realloc and calloc
1 parent d119d53 commit fb4e807

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
@@ -2042,8 +2042,8 @@ int freadMain(freadMainArgs _args) {
20422042
if (fill) INTERNAL_STOP("fill=true but there is a previous row which should already have been filled"); // # nocov
20432043
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);
20442044
fill = true;
2045-
type = (int8_t *)realloc(type, (size_t)tt * sizeof(int8_t));
2046-
tmpType = (int8_t *)realloc(tmpType, (size_t)tt * sizeof(int8_t));
2045+
type = realloc(type, sizeof(*type) * tt);
2046+
tmpType = realloc(tmpType, sizeof(*tmpType) * tt);
20472047
if (!type || !tmpType) STOP(_("Failed to realloc 2 x %d bytes for type and tmpType: %s"), tt, strerror(errno));
20482048
for (int j=ncol; j<tt; j++) { tmpType[j] = type[j] = type0; }
20492049
ncol = tt;
@@ -2141,9 +2141,9 @@ int freadMain(freadMainArgs _args) {
21412141
if (args.header==false) {
21422142
colNames = NULL; // userOverride will assign V1, V2, etc
21432143
} else {
2144-
colNames = (lenOff*) calloc((size_t)ncol, sizeof(lenOff));
2144+
colNames = calloc(ncol, sizeof(*colNames));
21452145
if (!colNames)
2146-
STOP(_("Unable to allocate %d*%d bytes for column name pointers: %s"), ncol, sizeof(lenOff), strerror(errno)); // # nocov
2146+
STOP(_("Unable to allocate %d*%d bytes for column name pointers: %s"), ncol, sizeof(*colNames), strerror(errno)); // # nocov
21472147
if (sep==' ') while (*ch==' ') ch++;
21482148
void *targets[9] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, colNames + autoFirstColName};
21492149
FieldParseContext fctx = {
@@ -2522,9 +2522,9 @@ int freadMain(freadMainArgs _args) {
25222522
(int)(tch-fieldStart), fieldStart, (uint64_t)(ctx.DTi+myNrow));
25232523
if (len > 1000) len = 1000;
25242524
if (len > 0) {
2525-
typeBumpMsg = (char*) realloc(typeBumpMsg, typeBumpMsgSize + (size_t)len + 1);
2525+
typeBumpMsg = realloc(typeBumpMsg, typeBumpMsgSize + len + 1);
25262526
strcpy(typeBumpMsg+typeBumpMsgSize, temp);
2527-
typeBumpMsgSize += (size_t)len;
2527+
typeBumpMsgSize += len;
25282528
}
25292529
}
25302530
nTypeBump++;

0 commit comments

Comments
 (0)