ecpg: check for strdup() failure - Mailing list pgsql-patches

From Neil Conway
Subject ecpg: check for strdup() failure
Date
Msg-id 42C49C32.2050704@samurai.com
Whole thread Raw
Responses Re: ecpg: check for strdup() failure
List pgsql-patches
Attached is a trivial improvement to ecpg's pgtypeslib: (1) `pstr' must
be non-NULL in this function, so no need to check for it (2) we should
check the return value of pgtypes_strdup(). Patch from Eric Astor at
EDB, with slight cleanup by myself, to fix a Coverity report.

Barring any objections I'll apply this to HEAD later today.

-Neil
Index: src/interfaces/ecpg/pgtypeslib/dt_common.c
===================================================================
RCS file: /var/lib/cvs/pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v
retrieving revision 1.23
diff -c -r1.23 dt_common.c
*** src/interfaces/ecpg/pgtypeslib/dt_common.c    24 May 2005 02:09:45 -0000    1.23
--- src/interfaces/ecpg/pgtypeslib/dt_common.c    30 Jun 2005 05:57:10 -0000
***************
*** 2669,2676 ****
      if (!pstr_end)
      {
          /* there was an error, no match */
!         err = 1;
!         return err;
      }
      last_char = *pstr_end;
      *pstr_end = '\0';
--- 2669,2675 ----
      if (!pstr_end)
      {
          /* there was an error, no match */
!         return 1;
      }
      last_char = *pstr_end;
      *pstr_end = '\0';
***************
*** 2699,2706 ****
                  err = 1;
              break;
          case PGTYPES_TYPE_STRING_MALLOCED:
!             if (pstr)
!                 scan_val->str_val = pgtypes_strdup(*pstr);
      }
      if (strtol_end && *strtol_end)
          *pstr = strtol_end;
--- 2698,2707 ----
                  err = 1;
              break;
          case PGTYPES_TYPE_STRING_MALLOCED:
!             scan_val->str_val = pgtypes_strdup(*pstr);
!             if (scan_val->str_val == NULL)
!                 err = 1;
!             break;
      }
      if (strtol_end && *strtol_end)
          *pstr = strtol_end;

pgsql-patches by date:

Previous
From: Greg Stark
Date:
Subject: Re: [HACKERS] Dbsize backend integration
Next
From: Neil Conway
Date:
Subject: ecpg: numeric_div error handling