Skip to content

Commit 44297a0

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 ba9eb29 commit 44297a0

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
@@ -756,18 +756,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
756756
{
757757
strcpy(mallocedval, "{");
758758

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

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

772763
strcpy(mallocedval + strlen(mallocedval) - 1, "}");
773764
}

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