1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-29 01:03:57 +03:00

string: Don't compare an array to null.

Found by Coverity.
This commit is contained in:
Andreas Schneider
2012-10-08 20:30:08 +02:00
parent 9338fb8e5e
commit 53008fb5d4

View File

@@ -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) { char *ssh_string_to_char(struct ssh_string_struct *s) {
size_t len; size_t len;
char *new; char *new;
if (s == NULL || s->data == NULL) if (s == NULL)
return NULL; return NULL;
len = ssh_string_len(s) + 1; len = ssh_string_len(s) + 1;
new = malloc(len); 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 *ssh_string_copy(struct ssh_string_struct *s) {
struct ssh_string_struct *new; struct ssh_string_struct *new;
size_t len;
if (s == NULL || s->data == NULL) { if (s == NULL) {
return NULL; return NULL;
} }
new = ssh_string_new(ssh_string_len(s)); len = ssh_string_len(s);
if (len == 0) {
return NULL;
}
new = ssh_string_new(len);
if (new == NULL) { if (new == NULL) {
return NULL; return NULL;
} }
memcpy(new->data, s->data, ssh_string_len(s)); memcpy(new->data, s->data, len);
return new; return new;
} }