Skip to content

Commit

Permalink
create_coboldata: prefer local buffers over temporary mallocs
Browse files Browse the repository at this point in the history
here only for USAGE DISPLAY (I have to merge in my local changes that I did for COMP-3 last year)
  • Loading branch information
GitMensch authored Apr 26, 2024
1 parent 524d1f5 commit 60de243
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions dblib/ocesql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2767,12 +2767,7 @@ create_coboldata(SQLVAR *sv, int index, char *retstr){

int fillzero;
int zcount;
char *final;
int finalbuflen;

// fill zero
finalbuflen = sv->length + TERMINAL_LENGTH;
final = (char *)calloc(finalbuflen, sizeof(char));
char final[MAX_DIGITS + 1 + TERMINAL_LENGTH] = { 0 };

// before decimal point
int beforedp = 0;
Expand Down Expand Up @@ -2813,7 +2808,6 @@ create_coboldata(SQLVAR *sv, int index, char *retstr){
}

memcpy(addr, final, sv->length);
free(final);
break;
}
case OCDB_TYPE_SIGNED_NUMBER_TC:
Expand All @@ -2824,14 +2818,9 @@ create_coboldata(SQLVAR *sv, int index, char *retstr){

int fillzero;
int zcount;
char *final;
int finalbuflen;
char final[MAX_DIGITS + SIGN_LENGTH + 1 + TERMINAL_LENGTH] = {0};
int final_length;

// fill zero
finalbuflen = sv->length;
final = (char *)calloc(finalbuflen, sizeof(char));

if(retstr[0] == '-'){
is_negative = true;
value = retstr + 1;
Expand Down Expand Up @@ -2883,7 +2872,6 @@ create_coboldata(SQLVAR *sv, int index, char *retstr){
}

memcpy(addr, final, sv->length);
free(final);
break;
}
case OCDB_TYPE_SIGNED_NUMBER_LS:
Expand All @@ -2893,12 +2881,7 @@ create_coboldata(SQLVAR *sv, int index, char *retstr){

int fillzero;
int zcount;
char *final;
int finalbuflen;

// fill zero
finalbuflen = SIGN_LENGTH + sv->length + TERMINAL_LENGTH;
final = (char *)calloc(finalbuflen, sizeof(char));
char final[MAX_DIGITS + SIGN_LENGTH + 1 + TERMINAL_LENGTH] = {0};

if(retstr[0] == '-'){
final[0] = '-';
Expand Down Expand Up @@ -2947,7 +2930,6 @@ create_coboldata(SQLVAR *sv, int index, char *retstr){
}

memcpy(addr, final, sv->length + SIGN_LENGTH);
free(final);
break;
}
case OCDB_TYPE_UNSIGNED_NUMBER_PD:
Expand Down

0 comments on commit 60de243

Please sign in to comment.