Fix warnings due to missing includes.
Check that comment != NULL if len > 0, avoid _zip_memdup with size 0.
--HG--
branch : HEAD
diff --git a/lib/zip_memdup.c b/lib/zip_memdup.c
index 20a2700..4f38a01 100644
--- a/lib/zip_memdup.c
+++ b/lib/zip_memdup.c
@@ -1,5 +1,5 @@
/*
- $NiH: zip_memdup.c,v 1.34 2006/04/09 19:05:47 wiz Exp $
+ $NiH: zip_memdup.c,v 1.1 2006/04/23 00:40:47 wiz Exp $
zip_memdup.c -- internal zip function, "strdup" with len
Copyright (C) 1999, 2003, 2004, 2005, 2006 Dieter Baron and Thomas Klausner
@@ -33,8 +33,8 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/types.h>
#include <stdlib.h>
+#include <string.h>
#include "zip.h"
#include "zipint.h"
diff --git a/lib/zip_set_archive_comment.c b/lib/zip_set_archive_comment.c
index 17fa344..86bb991 100644
--- a/lib/zip_set_archive_comment.c
+++ b/lib/zip_set_archive_comment.c
@@ -1,5 +1,5 @@
/*
- $NiH: zip_set_archive_comment.c,v 1.1 2006/04/23 00:40:48 wiz Exp $
+ $NiH: zip_set_archive_comment.c,v 1.2 2006/04/23 15:26:30 dillo Exp $
zip_set_archive_comment.c -- set archive comment
Copyright (C) 2006 Dieter Baron and Thomas Klausner
@@ -35,6 +35,8 @@
+#include <stdlib.h>
+
#include "zip.h"
#include "zipint.h"
@@ -45,13 +47,18 @@
{
char *tmpcom;
- if (len < 0 || len > MAXCOMLEN) {
+ if (len < 0 || len > MAXCOMLEN
+ || (len > 0 && comment == NULL)) {
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
}
- if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL)
- return -1;
+ if (len > 0) {
+ if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL)
+ return -1;
+ }
+ else
+ tmpcom = NULL;
free(za->ch_comment);
za->ch_comment = tmpcom;
diff --git a/lib/zip_set_file_comment.c b/lib/zip_set_file_comment.c
index 68e877e..28c8891 100644
--- a/lib/zip_set_file_comment.c
+++ b/lib/zip_set_file_comment.c
@@ -1,5 +1,5 @@
/*
- $NiH: zip_set_file_comment.c,v 1.2 2006/04/23 13:06:06 wiz Exp $
+ $NiH: zip_set_file_comment.c,v 1.3 2006/04/23 15:26:30 dillo Exp $
zip_set_file_comment.c -- set comment for file in archive
Copyright (C) 2006 Dieter Baron and Thomas Klausner
@@ -35,6 +35,8 @@
+#include <stdlib.h>
+
#include "zip.h"
#include "zipint.h"
@@ -45,18 +47,19 @@
{
char *tmpcom;
- if (idx < 0 || idx >= za->nentry) {
+ if (idx < 0 || idx >= za->nentry
+ || len < 0 || len > MAXCOMLEN
+ || (len > 0 && comment == NULL)) {
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return -1;
}
- if (len < 0 || len > MAXCOMLEN) {
- _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
- return -1;
+ if (len > 0) {
+ if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL)
+ return -1;
}
-
- if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL)
- return -1;
+ else
+ tmpcom = NULL;
free(za->entry[idx].ch_comment);
za->entry[idx].ch_comment = tmpcom;