Core Base Classes for the Light Endpoints

Dependencies:   BufferedSerial

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Revision:
51:73e837ee5aa6
Parent:
48:43fa2a43b114
Child:
54:d315b7c0a7a3
--- a/Resource.cpp	Sat Mar 01 19:23:41 2014 +0000
+++ b/Resource.cpp	Sun Mar 02 02:16:41 2014 +0000
@@ -41,15 +41,31 @@
  
  // get and set the name of the resource
  char *Resource::getName() { return this->m_name; }
- void Resource::setName(char *name) { if (name != NULL) strncpy(this->m_name,name,this->min(RESOURCE_NAME_LEN,strlen(name))); }
+ void Resource::setName(char *name) { 
+    if (name != NULL) {
+        memset(this->m_name,0,RESOURCE_NAME_LEN+1);
+        strncpy(this->m_name,name,this->min(RESOURCE_NAME_LEN,strlen(name))); 
+    }
+ }
  
  // get and set the value of the resource
  char *Resource::getValue() { this->extract(this->getName()); return this->getValuePointer(); }
  char *Resource::getValuePointer() { return this->m_value; }
- void Resource::setValue(char *value) { if (value != NULL) strncpy(this->m_value,value,this->min(RESOURCE_VALUE_LEN,strlen(value))); }
+ void Resource::setValue(char *value) { 
+    if (value != NULL) {
+        memset(this->m_value,0,RESOURCE_VALUE_LEN+1);
+        strncpy(this->m_value,value,this->min(RESOURCE_VALUE_LEN,strlen(value)));
+    } 
+ }
  
  // plumb the resource (base class does nothing other than save the endpoint_name)
- void Resource::plumb(char *endpoint_name,char *name) { if (endpoint_name != NULL) strncpy(this->m_endpoint_name,endpoint_name,this->min(LIGHT_NAME_LEN,strlen(endpoint_name))); }
+ void Resource::plumb(char *endpoint_name,char *name) { 
+    memset(this->m_endpoint_name,0,LIGHT_NAME_LEN+1);
+    if (endpoint_name != NULL) {
+        memset(this->m_endpoint_name,0,LIGHT_NAME_LEN+1);
+        strncpy(this->m_endpoint_name,endpoint_name,this->min(LIGHT_NAME_LEN,strlen(endpoint_name))); 
+    }
+ }
  
  // extract the resource value 
  void Resource::extract(char *name) {