Thread: ecpg: check for strdup() failure

ecpg: check for strdup() failure

From
Neil Conway
Date:
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;

Re: ecpg: check for strdup() failure

From
Neil Conway
Date:
Neil Conway wrote:
> 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.

Applied.

-Neil