diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/string.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/string.c b/src/string.c index a465d36d..b52e314b 100644 --- a/src/string.c +++ b/src/string.c @@ -164,7 +164,7 @@ const char *ssh_string_get_char(struct ssh_string_struct *s) char *ssh_string_to_char(struct ssh_string_struct *s) { size_t len; char *new; - if (s == NULL || s->data == NULL) + if (s == NULL) return NULL; len = ssh_string_len(s) + 1; new = malloc(len); @@ -196,17 +196,23 @@ void ssh_string_free_char(char *s) { */ struct ssh_string_struct *ssh_string_copy(struct ssh_string_struct *s) { struct ssh_string_struct *new; + size_t len; + + if (s == NULL) { + return NULL; + } - if (s == NULL || s->data == NULL) { + len = ssh_string_len(s); + if (len == 0) { return NULL; } - new = ssh_string_new(ssh_string_len(s)); + new = ssh_string_new(len); if (new == NULL) { return NULL; } - memcpy(new->data, s->data, ssh_string_len(s)); + memcpy(new->data, s->data, len); return new; } |