diff options
Diffstat (limited to 'src/nids.cpp')
-rw-r--r-- | src/nids.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/nids.cpp b/src/nids.cpp index d0cb843..a6596a2 100644 --- a/src/nids.cpp +++ b/src/nids.cpp | |||
@@ -3,7 +3,7 @@ | |||
3 | #include "bu/nidsstream.h" | 3 | #include "bu/nidsstream.h" |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | 5 | ||
6 | #define NIDS_MAGIC_CODE "\xFF\xC3\x99\xBD" | 6 | #define NIDS_MAGIC_CODE ((unsigned char *)"\xFF\xC3\x99\xBD") |
7 | 7 | ||
8 | namespace Bu | 8 | namespace Bu |
9 | { | 9 | { |
@@ -36,8 +36,10 @@ Bu::Nids::Nids( Bu::Stream &sStore ) : | |||
36 | sStore.isOpen()?"yes":"no" | 36 | sStore.isOpen()?"yes":"no" |
37 | ); | 37 | ); |
38 | printf("sizeof(Block) = %db\n", sizeof(Block) ); | 38 | printf("sizeof(Block) = %db\n", sizeof(Block) ); |
39 | 39 | printf("Magic: %02X%02X%02X%02X\n", | |
40 | 40 | NIDS_MAGIC_CODE[0], NIDS_MAGIC_CODE[1], | |
41 | NIDS_MAGIC_CODE[2], NIDS_MAGIC_CODE[3] | ||
42 | ); | ||
41 | } | 43 | } |
42 | 44 | ||
43 | Bu::Nids::~Nids() | 45 | Bu::Nids::~Nids() |
@@ -46,13 +48,16 @@ Bu::Nids::~Nids() | |||
46 | 48 | ||
47 | void Bu::Nids::initialize() | 49 | void Bu::Nids::initialize() |
48 | { | 50 | { |
49 | char buf[4]; | 51 | unsigned char buf[4]; |
50 | sStore.read( buf, 4 ); | 52 | if( sStore.read( buf, 4 ) < 4 ) |
53 | throw NidsException("Input stream appears to be empty."); | ||
51 | if( memcmp( buf, NIDS_MAGIC_CODE, 4 ) ) | 54 | if( memcmp( buf, NIDS_MAGIC_CODE, 4 ) ) |
52 | { | 55 | { |
53 | throw NidsException( | 56 | throw NidsException( |
54 | "Stream does not appear to be a valid NIDS format."); | 57 | "Stream does not appear to be a valid NIDS format."); |
55 | } | 58 | } |
59 | |||
60 | |||
56 | } | 61 | } |
57 | 62 | ||
58 | void Bu::Nids::initialize( int iBlockSize, int iPreAllocate ) | 63 | void Bu::Nids::initialize( int iBlockSize, int iPreAllocate ) |