Skip to content
Snippets Groups Projects
Commit 35a2dba2 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Shorten record list init and grow code.

parent fb2e2964
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
...@@ -33,8 +34,8 @@ void recordInitEntry(record_t *record) ...@@ -33,8 +34,8 @@ void recordInitEntry(record_t *record)
int recordNewEntry(stream_t *streamptr, int tsID) int recordNewEntry(stream_t *streamptr, int tsID)
{ {
int recordID = 0; size_t recordID = 0;
int recordSize = streamptr->tsteps[tsID].recordSize; size_t recordSize = (size_t)streamptr->tsteps[tsID].recordSize;
record_t *records = streamptr->tsteps[tsID].records; record_t *records = streamptr->tsteps[tsID].records;
/* /*
Look for a free slot in record. Look for a free slot in record.
...@@ -42,16 +43,10 @@ int recordNewEntry(stream_t *streamptr, int tsID) ...@@ -42,16 +43,10 @@ int recordNewEntry(stream_t *streamptr, int tsID)
*/ */
if ( ! recordSize ) if ( ! recordSize )
{ {
int i;
recordSize = 1; /* <<<<---- */ recordSize = 1; /* <<<<---- */
records = (record_t *) Malloc((size_t)recordSize * sizeof (record_t)); records = (record_t *) Malloc(recordSize * sizeof (record_t));
if ( records == NULL )
{
Message("recordSize = %d", recordSize);
SysError("Allocation of records failed");
}
for ( i = 0; i < recordSize; i++ ) for ( size_t i = 0; i < recordSize; i++ )
records[i].used = CDI_UNDEFID; records[i].used = CDI_UNDEFID;
} }
else else
...@@ -67,19 +62,16 @@ int recordNewEntry(stream_t *streamptr, int tsID) ...@@ -67,19 +62,16 @@ int recordNewEntry(stream_t *streamptr, int tsID)
*/ */
if ( recordID == recordSize ) if ( recordID == recordSize )
{ {
int i; if (recordSize <= INT_MAX / 2)
recordSize *= 2;
recordSize = 2*recordSize; else if (recordSize < INT_MAX)
records = (record_t *) Realloc(records, recordSize = INT_MAX;
(size_t)recordSize * sizeof (record_t)); else
if ( records == NULL ) Error("Cannot handle this many records!\n");
{ records = (record_t *) Realloc(records,
Message("recordSize = %d", recordSize); recordSize * sizeof (record_t));
SysError("Reallocation of records failed");
} for ( size_t i = recordID; i < recordSize; i++ )
recordID = recordSize/2;
for ( i = recordID; i < recordSize; i++ )
records[i].used = CDI_UNDEFID; records[i].used = CDI_UNDEFID;
} }
...@@ -87,10 +79,10 @@ int recordNewEntry(stream_t *streamptr, int tsID) ...@@ -87,10 +79,10 @@ int recordNewEntry(stream_t *streamptr, int tsID)
records[recordID].used = 1; records[recordID].used = 1;
streamptr->tsteps[tsID].recordSize = recordSize; streamptr->tsteps[tsID].recordSize = (int)recordSize;
streamptr->tsteps[tsID].records = records; streamptr->tsteps[tsID].records = records;
return (recordID); return (int)recordID;
} }
static static
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment