A small memory footprint AMQP implimentation

Dependents:   iothub_client_sample_amqp remote_monitoring simplesample_amqp

Revision:
23:1111ee8bcba4
Parent:
21:f9c433d8e6ca
Child:
24:2c59c2d43ebf
--- a/connection.c	Thu Apr 06 14:11:27 2017 -0700
+++ b/connection.c	Fri Apr 21 14:50:32 2017 -0700
@@ -957,7 +957,8 @@
                 {
                     if (hostname != NULL)
                     {
-                        result->host_name = (char*)malloc(strlen(hostname) + 1);
+                        size_t hostname_length = strlen(hostname);
+                        result->host_name = (char*)malloc(hostname_length + 1);
                         if (result->host_name == NULL)
                         {
                             /* Codes_SRS_CONNECTION_01_081: [If allocating the memory for the connection fails then connection_create shall return NULL.] */
@@ -968,7 +969,7 @@
                         }
                         else
                         {
-                            strcpy(result->host_name, hostname);
+                            (void)memcpy(result->host_name, hostname, hostname_length + 1);
                         }
                     }
                     else
@@ -978,7 +979,8 @@
 
                     if (result != NULL)
                     {
-                        result->container_id = (char*)malloc(strlen(container_id) + 1);
+                        size_t container_id_length = strlen(container_id);
+                        result->container_id = (char*)malloc(container_id_length + 1);
                         if (result->container_id == NULL)
                         {
                             /* Codes_SRS_CONNECTION_01_081: [If allocating the memory for the connection fails then connection_create shall return NULL.] */
@@ -1002,7 +1004,7 @@
                             }
                             else
                             {
-                                strcpy(result->container_id, container_id);
+                                (void)memcpy(result->container_id, container_id, container_id_length + 1);
 
                                 /* Codes_SRS_CONNECTION_01_173: [<field name="max-frame-size" type="uint" default="4294967295"/>] */
                                 result->max_frame_size = 4294967295u;
@@ -1481,7 +1483,7 @@
             }
 
             /* Codes_SRS_CONNECTION_01_127: [On success, connection_create_endpoint shall return a non-NULL handle to the newly created endpoint.] */
-            result = malloc(sizeof(ENDPOINT_INSTANCE));
+            result = (ENDPOINT_INSTANCE*)malloc(sizeof(ENDPOINT_INSTANCE));
             /* Codes_SRS_CONNECTION_01_196: [If memory cannot be allocated for the new endpoint, connection_create_endpoint shall fail and return NULL.] */
             if (result != NULL)
             {