]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - form/fld_def.c
ncurses 6.1 - patch 20191005
[ncurses.git] / form / fld_def.c
index 2aa14f776ace8e72bfd536ccf778f520eda53566..b18462f7b7f7598b7ca4bc9bceeacfa7f819c66c 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -32,7 +32,7 @@
 
 #include "form.priv.h"
 
-MODULE_ID("$Id: fld_def.c,v 1.34 2007/02/03 23:37:46 tom Exp $")
+MODULE_ID("$Id: fld_def.c,v 1.41 2014/07/26 21:08:55 tom Exp $")
 
 /* this can't be readonly */
 static FIELD default_field =
@@ -53,7 +53,7 @@ static FIELD default_field =
   (int)' ',                    /* pad     */
   A_NORMAL,                    /* fore    */
   A_NORMAL,                    /* back    */
-  ALL_FIELD_OPTS,              /* opts    */
+  STD_FIELD_OPTS,              /* opts    */
   (FIELD *)0,                  /* snext   */
   (FIELD *)0,                  /* sprev   */
   (FIELD *)0,                  /* link    */
@@ -65,8 +65,7 @@ static FIELD default_field =
   NCURSES_FIELD_EXTENSION
 };
 
-NCURSES_EXPORT_VAR(FIELD *)
-_nc_Default_Field = &default_field;
+NCURSES_EXPORT_VAR(FIELD *) _nc_Default_Field = &default_field;
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform
@@ -93,7 +92,7 @@ _nc_Make_Argument(const FIELDTYPE *typ, va_list *ap, int *err)
       assert(err != 0 && ap != (va_list *)0);
       if ((typ->status & _LINKED_TYPE) != 0)
        {
-         p = (TypeArgument *)malloc(sizeof(TypeArgument));
+         p = typeMalloc(TypeArgument, 1);
 
          if (p != 0)
            {
@@ -141,7 +140,7 @@ _nc_Copy_Argument(const FIELDTYPE *typ, const TypeArgument *argp, int *err)
       assert(err != 0 && argp != 0);
       if ((typ->status & _LINKED_TYPE) != 0)
        {
-         p = (TypeArgument *)malloc(sizeof(TypeArgument));
+         p = typeMalloc(TypeArgument, 1);
 
          if (p != 0)
            {
@@ -186,10 +185,12 @@ _nc_Free_Argument(const FIELDTYPE *typ, TypeArgument *argp)
     {
       if ((typ->status & _LINKED_TYPE) != 0)
        {
-         assert(argp != 0);
-         _nc_Free_Argument(typ->left, argp->left);
-         _nc_Free_Argument(typ->right, argp->right);
-         free(argp);
+         if (argp != 0)
+           {
+             _nc_Free_Argument(typ->left, argp->left);
+             _nc_Free_Argument(typ->right, argp->right);
+             free(argp);
+           }
        }
       else
        {
@@ -252,8 +253,8 @@ _nc_Free_Type(FIELD *field)
   if (field->type != 0)
     {
       field->type->ref--;
+      _nc_Free_Argument(field->type, (TypeArgument *)(field->arg));
     }
-  _nc_Free_Argument(field->type, (TypeArgument *)(field->arg));
 }
 
 /*---------------------------------------------------------------------------
@@ -289,23 +290,23 @@ new_field(int rows, int cols, int frow, int fcol, int nrow, int nbuf)
       nrow >= 0 &&
       nbuf >= 0 &&
       ((err = E_SYSTEM_ERROR) != 0) && /* trick: this resets the default error */
-      (New_Field = (FIELD *)malloc(sizeof(FIELD))) != 0)
+      (New_Field = typeMalloc(FIELD, 1)) != 0)
     {
-      T((T_CREATE("field %p"), New_Field));
+      T((T_CREATE("field %p"), (void *)New_Field));
       *New_Field = default_field;
-      New_Field->rows = rows;
-      New_Field->cols = cols;
+      New_Field->rows = (short)rows;
+      New_Field->cols = (short)cols;
       New_Field->drows = rows + nrow;
       New_Field->dcols = cols;
-      New_Field->frow = frow;
-      New_Field->fcol = fcol;
+      New_Field->frow = (short)frow;
+      New_Field->fcol = (short)fcol;
       New_Field->nrow = nrow;
-      New_Field->nbuf = nbuf;
+      New_Field->nbuf = (short)nbuf;
       New_Field->link = New_Field;
 
 #if USE_WIDEC_SUPPORT
       New_Field->working = newpad(1, Buffer_Length(New_Field) + 1);
-      New_Field->expanded = (char **)calloc(1 + (unsigned)rows, sizeof(char *));
+      New_Field->expanded = typeCalloc(char *, 1 + (unsigned)nbuf);
 #endif
 
       if (_nc_Copy_Type(New_Field, &default_field))
@@ -355,7 +356,7 @@ new_field(int rows, int cols, int frow, int fcol, int nrow, int nbuf)
 NCURSES_EXPORT(int)
 free_field(FIELD *field)
 {
-  T((T_CALLED("free_field(%p)"), field));
+  T((T_CALLED("free_field(%p)"), (void *)field));
   if (!field)
     {
       RETURN(E_BAD_ARGUMENT);