[asterisk-commits] kmoore: branch kmoore/cel_backend_refactor r396089 - /team/kmoore/cel_backend...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 2 08:13:21 CDT 2013


Author: kmoore
Date: Fri Aug  2 08:13:17 2013
New Revision: 396089

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396089
Log:
Use a flexible array member instead of string fields

Modified:
    team/kmoore/cel_backend_refactor/main/cel.c

Modified: team/kmoore/cel_backend_refactor/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_backend_refactor/main/cel.c?view=diff&rev=396089&r1=396088&r2=396089
==============================================================================
--- team/kmoore/cel_backend_refactor/main/cel.c (original)
+++ team/kmoore/cel_backend_refactor/main/cel.c Fri Aug  2 08:13:17 2013
@@ -330,19 +330,9 @@
 };
 
 struct cel_backend {
-	AST_DECLARE_STRING_FIELDS(
-		AST_STRING_FIELD(name);	/*!< Name of this backend */
-	);
-	ast_cel_backend_cb callback;	/*!< Callback for this backend */
+	ast_cel_backend_cb callback; /*!< Callback for this backend */
+	char name[0];                /*!< Name of this backend */
 };
-
-/*! \brief Backend destructor */
-static void cel_backend_dtor(void *obj)
-{
-	struct cel_backend *backend = obj;
-	ast_string_field_free_memory(backend);
-	backend->callback = NULL;
-}
 
 /*! \brief Hashing function for cel_backend */
 static int cel_backend_hash(const void *obj, int flags)
@@ -1771,12 +1761,13 @@
 		return -1;
 	}
 
-	backend = ao2_alloc(sizeof(*backend), cel_backend_dtor);
-	if (!backend || ast_string_field_init(backend, 32)) {
-		return -1;
-	}
-
-	ast_string_field_set(backend, name, name);
+	backend = ao2_alloc(sizeof(*backend) + 1 + strlen(name), NULL);
+	if (!backend) {
+		return -1;
+	}
+
+	/* safe strcpy */
+	strcpy(backend->name, name);
 	backend->callback = backend_callback;
 	ao2_link(cel_backends, backend);
 




More information about the asterisk-commits mailing list