Skip to content

Commit 6af0808

Browse files
committed
One more round of fixing compilation errors with VS2008
1 parent 13ae8dc commit 6af0808

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

src/api/Compressor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ int CDECL initCompressor(struct cData* pData, FILE* dst, struct cContext** pCtx)
144144
cctx->fos = fos;
145145
*pCtx = cctx;
146146
}
147-
catch (const exception& e) {
147+
catch (const exception&) {
148148
if (fos != nullptr)
149149
delete fos;
150150

src/api/Compressor.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ limitations under the License.
2424
#endif
2525

2626
#include <stdio.h>
27-
#include <stdint.h>
2827

2928

3029
#ifdef __cplusplus

src/api/Decompressor.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,34 @@ namespace kanzi {
4949
char _buffer[BUF_SIZE];
5050

5151
virtual int_type underflow() {
52-
if (gptr() < egptr())
53-
return traits_type::to_int_type(*gptr());
52+
if (gptr() < egptr())
53+
return traits_type::to_int_type(*gptr());
5454

55-
// Preserve up to 4 bytes of putback
56-
const int putback = std::min<int>(gptr() - eback(), 4);
55+
// Number of characters to preserve (putback)
56+
int putback = int(gptr() - eback());
5757

58-
// Move putback bytes to the front
59-
std::memmove(_buffer + (4 - putback), gptr() - putback, putback);
58+
if (putback > 4) putback = 4;
6059

61-
// Read new bytes after putback
62-
const int n = READ(_fd, _buffer + 4, BUF_SIZE - 4);
63-
if (n <= 0)
64-
return traits_type::eof();
60+
// Prevent reading before buffer start
61+
const char* src = gptr() - putback;
6562

66-
// Set new buffer pointers
67-
setg(_buffer + (4 - putback), _buffer + 4, _buffer + 4 + n);
68-
return traits_type::to_int_type(*gptr());
69-
}
63+
if (src < _buffer) {
64+
putback = int(gptr() - _buffer);
65+
src = _buffer;
66+
}
67+
68+
// Move putback characters to start of buffer
69+
std::memmove(_buffer + (4 - putback), src, putback);
70+
71+
// Read new characters into buffer
72+
const int n = int(READ(_fd, _buffer + 4, BUF_SIZE - 4));
73+
74+
if (n <= 0)
75+
return EOF;
76+
77+
setg(_buffer + (4 - putback), _buffer + 4, _buffer + 4 + n);
78+
return traits_type::to_int_type(*gptr());
79+
}
7080
};
7181

7282
class FileInputStream FINAL : public istream

src/types.hpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,27 @@ limitations under the License.
1717
#ifndef _types_
1818
#define _types_
1919

20-
#ifdef _MSC_VER
20+
#if defined(_MSC_VER) && _MSC_VER < 1600
21+
// Visual Studio < 2010: no stdint.h
22+
typedef unsigned char uint8_t;
23+
typedef signed char int8_t;
24+
typedef unsigned short uint16_t;
25+
typedef short int16_t;
26+
typedef unsigned int uint32_t;
27+
typedef int int32_t;
28+
typedef unsigned __int64 uint64_t;
29+
typedef __int64 int64_t;
30+
#else
31+
// Modern compilers
32+
#include <cstdint>
33+
#endif
34+
35+
#if defined(_MSC_VER)
36+
#if _MSC_VER < 1900
37+
// snprintf macro for MSVC < 2015
38+
#define snprintf _snprintf
39+
#endif
40+
2141
#if !defined(__x86_64__)
2242
#define __x86_64__ _M_X64
2343
#endif

0 commit comments

Comments
 (0)