1- /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.86 2009/08/07 10:51:20 meskes Exp $ */
1+ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.87 2009/09/03 10:24:48 meskes Exp $ */
22
33/*
44 * The aim is to get a simpler inteface to the database routines.
@@ -469,8 +469,8 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
469469 char * newcopy = NULL ;
470470
471471 /*
472- * arrays are not possible unless the attribute is an array too FIXME: we
473- * do not know if the attribute is an array here
472+ * arrays are not possible unless the attribute is an array too
473+ * FIXME: we do not know if the attribute is an array here
474474 */
475475#if 0
476476 if (var -> arrsize > 1 && ...)
@@ -818,6 +818,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
818818
819819 if (var -> arrsize > 1 )
820820 {
821+ if (!(mallocedval = ecpg_strdup ("array [" , lineno )))
822+ return false;
823+
821824 for (element = 0 ; element < var -> arrsize ; element ++ )
822825 {
823826 nval = PGTYPESnumeric_new ();
@@ -833,15 +836,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
833836 slen = strlen (str );
834837 PGTYPESnumeric_free (nval );
835838
836- if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + sizeof ( "array [] " ) , lineno )))
839+ if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + 2 , lineno )))
837840 {
838841 ecpg_free (str );
839842 return false;
840843 }
841844
842- if (!element )
843- strcpy (mallocedval , "array [" );
844-
845845 strncpy (mallocedval + strlen (mallocedval ), str , slen + 1 );
846846 strcpy (mallocedval + strlen (mallocedval ), "," );
847847 ecpg_free (str );
@@ -885,22 +885,22 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
885885
886886 if (var -> arrsize > 1 )
887887 {
888+ if (!(mallocedval = ecpg_strdup ("array [" , lineno )))
889+ return false;
890+
888891 for (element = 0 ; element < var -> arrsize ; element ++ )
889892 {
890893 str = quote_postgres (PGTYPESinterval_to_asc ((interval * ) ((var + var -> offset * element )-> value )), quote , lineno );
891894 if (!str )
892895 return false;
893896 slen = strlen (str );
894897
895- if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + sizeof ( "array [],interval " ) , lineno )))
898+ if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + 2 , lineno )))
896899 {
897900 ecpg_free (str );
898901 return false;
899902 }
900903
901- if (!element )
902- strcpy (mallocedval , "array [" );
903-
904904 strncpy (mallocedval + strlen (mallocedval ), str , slen + 1 );
905905 strcpy (mallocedval + strlen (mallocedval ), "," );
906906 ecpg_free (str );
@@ -936,22 +936,22 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
936936
937937 if (var -> arrsize > 1 )
938938 {
939+ if (!(mallocedval = ecpg_strdup ("array [" , lineno )))
940+ return false;
941+
939942 for (element = 0 ; element < var -> arrsize ; element ++ )
940943 {
941944 str = quote_postgres (PGTYPESdate_to_asc (* (date * ) ((var + var -> offset * element )-> value )), quote , lineno );
942945 if (!str )
943946 return false;
944947 slen = strlen (str );
945948
946- if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + sizeof ( "array [],date " ) , lineno )))
949+ if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + 2 , lineno )))
947950 {
948951 ecpg_free (str );
949952 return false;
950953 }
951954
952- if (!element )
953- strcpy (mallocedval , "array [" );
954-
955955 strncpy (mallocedval + strlen (mallocedval ), str , slen + 1 );
956956 strcpy (mallocedval + strlen (mallocedval ), "," );
957957 ecpg_free (str );
@@ -987,6 +987,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
987987
988988 if (var -> arrsize > 1 )
989989 {
990+ if (!(mallocedval = ecpg_strdup ("array [" , lineno )))
991+ return false;
992+
990993 for (element = 0 ; element < var -> arrsize ; element ++ )
991994 {
992995 str = quote_postgres (PGTYPEStimestamp_to_asc (* (timestamp * ) ((var + var -> offset * element )-> value )), quote , lineno );
@@ -995,15 +998,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
995998
996999 slen = strlen (str );
9971000
998- if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + sizeof ( "array [], timestamp " ) , lineno )))
1001+ if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + 2 , lineno )))
9991002 {
10001003 ecpg_free (str );
10011004 return false;
10021005 }
10031006
1004- if (!element )
1005- strcpy (mallocedval , "array [" );
1006-
10071007 strncpy (mallocedval + strlen (mallocedval ), str , slen + 1 );
10081008 strcpy (mallocedval + strlen (mallocedval ), "," );
10091009 ecpg_free (str );
0 commit comments