char **CellContents=NULL;
int i;
- if ( (CellContents=(char **) malloc( sizeof(char *) * Table->numColumns))\
- == NULL ) {
+ if ( (CellContents=malloc( sizeof(char *) * Table->numColumns))== NULL ) {
fprintf(stderr,"Internal Error. Cannot allocate memory for new CellContents-array.\n");
exit(EXIT_FAILURE);
}
for (i=0;i<Table->numColumns;i++) {
- if ( (CellContents[i]=(char *) malloc(UTIL_T_MAX_CELLCONTENT_LEN)) == NULL) {
+ if ( (CellContents[i]=malloc(UTIL_T_MAX_CELLCONTENT_LEN)) == NULL) {
fprintf(stderr,\
"Internal Error. Cannot allocate memory for new CellContents-array.\n");
exit(EXIT_FAILURE);
Table->Type=Type;
Table->numColumns=numColumns;
Table->numRows=0;
+ Table->numAllocatedRows=0;
if (sortByColumn < 0 || sortByColumn > numColumns) {
fprintf(stderr,"Invalid Table Sortkey: %d.\n", sortByColumn);
errno=EINVAL;
+ free(Table);
return NULL;
}
if (sortByColumn > 0 )
break;
default :
fprintf(stderr,"Error. Invalid TableType: %d.\n", Table->Type);
+ free(Table);
errno=EINVAL;
return NULL;
}
newTableRow(struct util_Table* Table) {
struct util_TableRow *aRow =NULL;
- if ( (aRow= (struct util_TableRow*) malloc(sizeof(struct util_TableRow))) == NULL) {
+ if ( (aRow = malloc(sizeof(struct util_TableRow))) == NULL) {
fprintf(stderr,\
"Internal Error. Cannot allocate memory for new TableRow.\n");
exit(EXIT_FAILURE);
/* find correct index for new row by bi-secting the table */
int
findRowIndex(struct util_Table* Table, struct util_TableRow *aRow){
- int cmp,best,lower,middle,upper;
+ int cmp,lower,middle,upper;
/* empty Table */
if (Table->numRows == 0) {
lower = 0;
upper= Table->numRows-1;
- best=0;
do {
middle=(upper-lower)/2+lower;
cmp=compareBodyRow(Table,middle,aRow);
if (cmp > 0) {
upper=middle;
- best = lower;
}
if (cmp < 0) {
lower=middle;
- best = upper;
}
if (cmp == 0) {
return middle;