diff --git a/apps/json-resource/generic_resource.c b/apps/json-resource/generic_resource.c index 53c497490..9ac8ac93b 100644 --- a/apps/json-resource/generic_resource.c +++ b/apps/json-resource/generic_resource.c @@ -189,8 +189,10 @@ void generic_put_handler if (from_str && (len = coap_get_payload(request, &bytes))) { if (c_ctype == REST.type.TEXT_PLAIN) { + int l = MIN (len, sizeof (temp) - 1); temp [sizeof (temp) - 1] = 0; - strncpy (temp, (const char *)bytes, MIN (len, sizeof (temp) - 1)); + strncpy (temp, (const char *)bytes, l); + temp [l] = 0; } else { // jSON Format if (json_parse_variable (bytes, len, name, temp, sizeof (temp)) < 0) { success = 0; diff --git a/examples/osd/poti/poti.c b/examples/osd/poti/poti.c index 7044cde55..c57f119c8 100644 --- a/examples/osd/poti/poti.c +++ b/examples/osd/poti/poti.c @@ -203,18 +203,7 @@ PROCESS_THREAD(poti, ev, data) char buf [4]; coap_transaction_t *transaction; - /* - * Note: A sending transaction may be still in progress when - * we call the following code. This means that the *new* - * value in the transaction buffer will overwrite the old - * value *but* the old length remains. This means if we - * first send 255 (and the transaction sending 255 is still - * in progress) and we now send 0, the resulting buffer is - * 055 (because only the 0 is copied but the old length - * stays). Therefore as a workaround we *always* send a - * 3-byte value. - */ - sprintf (buf, "%03d", val); + sprintf (buf, "%d", val); lastval = val; printf ("Sending Value: %s\n", buf); coap_init_message (request, COAP_TYPE_NON, COAP_PUT, 0);