Skip to content

Commit f38070d

Browse files
author
Michael Meskes
committed
Let compiler handle size calculation of bool types.
Back in the day this did not work, but modern compilers should handle it themselves.
1 parent f7d896a commit f38070d

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

src/interfaces/ecpg/ecpglib/data.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -422,27 +422,13 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
422422
case ECPGt_bool:
423423
if (pval[0] == 'f' && pval[1] == '\0')
424424
{
425-
if (offset == sizeof(char))
426-
*((char *) (var + offset * act_tuple)) = false;
427-
else if (offset == sizeof(int))
428-
*((int *) (var + offset * act_tuple)) = false;
429-
else
430-
ecpg_raise(lineno, ECPG_CONVERT_BOOL,
431-
ECPG_SQLSTATE_DATATYPE_MISMATCH,
432-
NULL);
425+
*((bool *) (var + offset * act_tuple)) = false;
433426
pval++;
434427
break;
435428
}
436429
else if (pval[0] == 't' && pval[1] == '\0')
437430
{
438-
if (offset == sizeof(char))
439-
*((char *) (var + offset * act_tuple)) = true;
440-
else if (offset == sizeof(int))
441-
*((int *) (var + offset * act_tuple)) = true;
442-
else
443-
ecpg_raise(lineno, ECPG_CONVERT_BOOL,
444-
ECPG_SQLSTATE_DATATYPE_MISMATCH,
445-
NULL);
431+
*((bool *) (var + offset * act_tuple)) = true;
446432
pval++;
447433
break;
448434
}

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -752,18 +752,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
752752
{
753753
strcpy(mallocedval, "{");
754754

755-
if (var->offset == sizeof(char))
756-
for (element = 0; element < asize; element++)
757-
sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');
755+
for (element = 0; element < asize; element++)
756+
sprintf(mallocedval + strlen(mallocedval), "%c,", (((bool *) var->value)[element]) ? 't' : 'f');
758757

759-
/*
760-
* this is necessary since sizeof(C++'s bool)==sizeof(int)
761-
*/
762-
else if (var->offset == sizeof(int))
763-
for (element = 0; element < asize; element++)
764-
sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f');
765-
else
766-
ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
767758

768759
strcpy(mallocedval + strlen(mallocedval) - 1, "}");
769760
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy