diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2012-10-08 20:30:08 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2012-10-12 08:07:01 +0200 |
commit | 53008fb5d4708e956c7647dac25dabf74858cc59 (patch) | |
tree | 790636b6686ac01d162b038e385f058c212bf69e /src | |
parent | 9338fb8e5e98c019b395d4a5108733118761a951 (diff) | |
download | libssh-53008fb5d4708e956c7647dac25dabf74858cc59.tar.gz libssh-53008fb5d4708e956c7647dac25dabf74858cc59.tar.xz libssh-53008fb5d4708e956c7647dac25dabf74858cc59.zip |
string: Don't compare an array to null.
Found by Coverity.
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 a465d36..b52e314 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; } |