aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2012-10-08 20:30:08 +0200
committerAndreas Schneider <asn@cryptomilk.org>2012-10-12 08:07:01 +0200
commit53008fb5d4708e956c7647dac25dabf74858cc59 (patch)
tree790636b6686ac01d162b038e385f058c212bf69e /src
parent9338fb8e5e98c019b395d4a5108733118761a951 (diff)
downloadlibssh-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.c14
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;
}