aboutsummaryrefslogtreecommitdiffstats
path: root/skeletons
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2005-12-17 11:43:25 +0000
committerLev Walkin <vlm@lionet.info>2005-12-17 11:43:25 +0000
commit7b284818e9671f6427ee9580ddf43b74fa017df3 (patch)
tree1f906d2524cdebbeb43df21ea0a7240dfe2952d2 /skeletons
parent1d9e8dd64e13be94e4253a65d56c258de9a34c8f (diff)
robust fromBuf
Diffstat (limited to 'skeletons')
-rw-r--r--skeletons/OCTET_STRING.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/skeletons/OCTET_STRING.c b/skeletons/OCTET_STRING.c
index fe29f83f..c9d51487 100644
--- a/skeletons/OCTET_STRING.c
+++ b/skeletons/OCTET_STRING.c
@@ -1399,8 +1399,8 @@ OCTET_STRING_fromBuf(OCTET_STRING_t *st, const char *str, int len) {
* Clear the OCTET STRING.
*/
if(str == NULL) {
- if(st->buf)
- FREEMEM(st->buf);
+ FREEMEM(st->buf);
+ st->buf = 0;
st->size = 0;
return 0;
}
@@ -1411,15 +1411,14 @@ OCTET_STRING_fromBuf(OCTET_STRING_t *st, const char *str, int len) {
/* Allocate and fill the memory */
buf = MALLOC(len + 1);
- if(buf == NULL) {
+ if(buf == NULL)
return -1;
- } else {
- st->buf = (uint8_t *)buf;
- st->size = len;
- }
memcpy(buf, str, len);
- st->buf[st->size] = '\0'; /* Couldn't use memcpy(len+1)! */
+ ((uint8_t *)buf)[len] = '\0'; /* Couldn't use memcpy(len+1)! */
+ FREEMEM(st->buf);
+ st->buf = (uint8_t *)buf;
+ st->size = len;
return 0;
}