updated on Tue Jan 10 12:02:00 UTC 2012
[aur-mirror.git] / atlas_cpp / compression.patch
blob69c899d073e0ea2d25b124a7d61c0f567d111f46
1 From cf86c5ad8799635ea0458c6d4fbfb90ef5c53651 Mon Sep 17 00:00:00 2001
2 From: Alistair Riddoch <alriddoch@googlemail.com>
3 Date: Mon, 2 May 2011 11:54:09 +0100
4 Subject: [PATCH] Add more correct handling of compression errors
6 ---
7 Atlas/Filters/Bzip2.cpp | 43 +++++++++++++++++++++++--------------------
8 Atlas/Filters/Gzip.cpp | 40 +++++++++++++++++++++-------------------
9 2 files changed, 44 insertions(+), 39 deletions(-)
11 diff --git a/Atlas/Filters/Bzip2.cpp b/Atlas/Filters/Bzip2.cpp
12 index 4cbe987..780bb45 100644
13 --- a/Atlas/Filters/Bzip2.cpp
14 +++ b/Atlas/Filters/Bzip2.cpp
15 @@ -56,16 +56,17 @@ std::string Bzip2::encode(const std::string& data)
17 do
19 - outgoing.next_out = buf;
20 - outgoing.avail_out = sizeof(buf);
22 - status = BZ2_bzCompress(&outgoing, BZ_FLUSH);
24 - ASSERT(status == BZ_OK); // not sure about this - it may be
25 - // status != BZ_SEQUENCE_ERROR
27 - out_string.append((char*)buf, sizeof(buf) - outgoing.avail_out);
29 + outgoing.next_out = buf;
30 + outgoing.avail_out = sizeof(buf);
32 + status = BZ2_bzCompress(&outgoing, BZ_FLUSH);
34 + ASSERT(status != BZ_SEQUENCE_ERROR);
36 + if (status != BZ_SEQUENCE_ERROR) {
37 + out_string.append((char*)buf, sizeof(buf) - outgoing.avail_out);
38 + }
39 + // FIXME do something else in case of error?
40 } while (outgoing.avail_out == 0);
42 return out_string;
43 @@ -81,17 +82,19 @@ std::string Bzip2::decode(const std::string& data)
44 incoming.next_in = (char*)data.data();
45 incoming.avail_in = data.size();
47 - do
48 + do
50 - incoming.next_out = buf;
51 - incoming.avail_out = sizeof(buf);
53 - status = BZ2_bzDecompress(&incoming);
55 - ASSERT(status == BZ_OK);
57 - out_string.append((char*)buf, sizeof(buf) - incoming.avail_out);
59 + incoming.next_out = buf;
60 + incoming.avail_out = sizeof(buf);
62 + status = BZ2_bzDecompress(&incoming);
64 + ASSERT(status == BZ_OK);
66 + if (status != BZ_SEQUENCE_ERROR) {
67 + out_string.append((char*)buf, sizeof(buf) - incoming.avail_out);
68 + }
70 } while(incoming.avail_out == 0);
72 return out_string;
73 diff --git a/Atlas/Filters/Gzip.cpp b/Atlas/Filters/Gzip.cpp
74 index f17db69..cbeee1f 100644
75 --- a/Atlas/Filters/Gzip.cpp
76 +++ b/Atlas/Filters/Gzip.cpp
77 @@ -51,17 +51,18 @@ std::string Gzip::encode(const std::string& data)
78 outgoing.next_in = (unsigned char *)data.data();
79 outgoing.avail_in = data.size();
81 - do
82 + do
84 - outgoing.next_out = buf;
85 - outgoing.avail_out = sizeof(buf);
87 - status = deflate(&outgoing, Z_SYNC_FLUSH);
89 - ASSERT(status == Z_OK);
91 - out_string.append((char*)buf, sizeof(buf) - outgoing.avail_out);
93 + outgoing.next_out = buf;
94 + outgoing.avail_out = sizeof(buf);
96 + status = deflate(&outgoing, Z_SYNC_FLUSH);
98 + ASSERT(status == Z_OK);
100 + if (status >= 0) {
101 + out_string.append((char*)buf, sizeof(buf) - outgoing.avail_out);
103 } while (outgoing.avail_out == 0);
105 return out_string;
106 @@ -79,15 +80,16 @@ std::string Gzip::decode(const std::string& data)
110 - incoming.next_out = buf;
111 - incoming.avail_out = sizeof(buf);
113 - status = inflate(&incoming, Z_SYNC_FLUSH);
115 - ASSERT(status == Z_OK);
117 - out_string.append((char*)buf, sizeof(buf) - incoming.avail_out);
119 + incoming.next_out = buf;
120 + incoming.avail_out = sizeof(buf);
122 + status = inflate(&incoming, Z_SYNC_FLUSH);
124 + ASSERT(status == Z_OK);
126 + if (status >= 0) {
127 + out_string.append((char*)buf, sizeof(buf) - incoming.avail_out);
129 } while(incoming.avail_out == 0);
131 return out_string;
133 1.7.4.1