Improve internal data structures. New extra field API (read only).
Added paranoid mode to zipcmp (compare more meta data).
Keep up-to-date metadata for changed entries, avoid parallel arrays.
XXX: Modifying extra fields API functions are stubs. Old API removed.
diff --git a/lib/zip_set_archive_comment.c b/lib/zip_set_archive_comment.c
index bbb9a73..f71bea7 100644
--- a/lib/zip_set_archive_comment.c
+++ b/lib/zip_set_archive_comment.c
@@ -42,7 +42,12 @@
ZIP_EXTERN int
zip_set_archive_comment(struct zip *za, const char *comment, int len)
{
- char *tmpcom;
+ struct zip_string *cstr;
+
+ if (ZIP_IS_RDONLY(za)) {
+ _zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
+ return -1;
+ }
if (len < 0 || len > MAXCOMLEN
|| (len > 0 && comment == NULL)) {
@@ -50,26 +55,31 @@
return -1;
}
- if (ZIP_IS_RDONLY(za)) {
- _zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
- return -1;
- }
-
- if (_zip_guess_encoding(comment, len) == ZIP_ENCODING_CP437) {
- _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
- return -1;
- }
-
if (len > 0) {
- if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL)
+ if ((cstr=_zip_string_new((const zip_uint8_t *)comment, len, &za->error)) == NULL)
return -1;
+
+ if (_zip_guess_encoding(cstr, ZIP_ENCODING_UNKNOWN) == ZIP_ENCODING_CP437) {
+ _zip_string_free(cstr);
+ _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
}
else
- tmpcom = NULL;
+ cstr = NULL;
- free(za->ch_comment);
- za->ch_comment = tmpcom;
- za->ch_comment_len = len;
+ _zip_string_free(za->comment_changes);
+ za->comment_changes = NULL;
+
+ if (((za->comment_orig && _zip_string_equal(za->comment_orig, cstr))
+ || (za->comment_orig == NULL && cstr == NULL))) {
+ _zip_string_free(cstr);
+ za->comment_changed = 0;
+ }
+ else {
+ za->comment_changes = cstr;
+ za->comment_changed = 1;
+ }
return 0;
}