diff options
| author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-06-20 00:00:00 +0000 |
|---|---|---|
| committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-12-17 13:35:20 +0500 |
| commit | a3e1d227377188734b82f023f96f8e25dc40f3e6 (patch) | |
| tree | 23cad8d47eb23d26ea727b4f7f4a65124f724065 /CPP/Common | |
| parent | f19f813537c7aea1c20749c914e756b54a9c3cf5 (diff) | |
| download | 7zip-22.00.tar.gz 7zip-22.00.tar.bz2 7zip-22.00.zip | |
22.0022.00
Diffstat (limited to '')
| -rw-r--r-- | CPP/Common/Common.h | 2 | ||||
| -rw-r--r-- | CPP/Common/MyCom.h | 1 | ||||
| -rw-r--r-- | CPP/Common/MyLinux.h | 33 | ||||
| -rw-r--r-- | CPP/Common/MyString.cpp | 187 | ||||
| -rw-r--r-- | CPP/Common/MyString.h | 3 | ||||
| -rw-r--r-- | CPP/Common/MyVector.h | 215 | ||||
| -rw-r--r-- | CPP/Common/MyWindows.h | 2 | ||||
| -rw-r--r-- | CPP/Common/NewHandler.cpp | 19 | ||||
| -rw-r--r-- | CPP/Common/StringToInt.cpp | 27 | ||||
| -rw-r--r-- | CPP/Common/StringToInt.h | 1 |
10 files changed, 339 insertions, 151 deletions
diff --git a/CPP/Common/Common.h b/CPP/Common/Common.h index 8dac613..72db7a8 100644 --- a/CPP/Common/Common.h +++ b/CPP/Common/Common.h | |||
| @@ -35,7 +35,7 @@ you can change this h file or h files included in this file. | |||
| 35 | So we can use MY_ARRAY_NEW macro instead of new[] operator. */ | 35 | So we can use MY_ARRAY_NEW macro instead of new[] operator. */ |
| 36 | 36 | ||
| 37 | #if defined(_MSC_VER) && (_MSC_VER == 1200) && !defined(_WIN64) | 37 | #if defined(_MSC_VER) && (_MSC_VER == 1200) && !defined(_WIN64) |
| 38 | #define MY_ARRAY_NEW(p, T, size) p = new T[(size > (unsigned)0xFFFFFFFF / sizeof(T)) ? (unsigned)0xFFFFFFFF / sizeof(T) : size]; | 38 | #define MY_ARRAY_NEW(p, T, size) p = new T[((size) > (unsigned)0xFFFFFFFF / sizeof(T)) ? (unsigned)0xFFFFFFFF / sizeof(T) : (size)]; |
| 39 | #else | 39 | #else |
| 40 | #define MY_ARRAY_NEW(p, T, size) p = new T[size]; | 40 | #define MY_ARRAY_NEW(p, T, size) p = new T[size]; |
| 41 | #endif | 41 | #endif |
diff --git a/CPP/Common/MyCom.h b/CPP/Common/MyCom.h index ce2f0dd..ff54278 100644 --- a/CPP/Common/MyCom.h +++ b/CPP/Common/MyCom.h | |||
| @@ -67,6 +67,7 @@ public: | |||
| 67 | template <class Q> | 67 | template <class Q> |
| 68 | HRESULT QueryInterface(REFGUID iid, Q** pp) const throw() | 68 | HRESULT QueryInterface(REFGUID iid, Q** pp) const throw() |
| 69 | { | 69 | { |
| 70 | // if (*pp) throw 20220216; // for debug | ||
| 70 | return _p->QueryInterface(iid, (void**)pp); | 71 | return _p->QueryInterface(iid, (void**)pp); |
| 71 | } | 72 | } |
| 72 | }; | 73 | }; |
diff --git a/CPP/Common/MyLinux.h b/CPP/Common/MyLinux.h index 1a91899..98b453c 100644 --- a/CPP/Common/MyLinux.h +++ b/CPP/Common/MyLinux.h | |||
| @@ -3,6 +3,18 @@ | |||
| 3 | #ifndef __MY_LIN_LINUX_H | 3 | #ifndef __MY_LIN_LINUX_H |
| 4 | #define __MY_LIN_LINUX_H | 4 | #define __MY_LIN_LINUX_H |
| 5 | 5 | ||
| 6 | // #include "../../C/7zTypes.h" | ||
| 7 | |||
| 8 | #define MY_LIN_DT_UNKNOWN 0 | ||
| 9 | #define MY_LIN_DT_FIFO 1 | ||
| 10 | #define MY_LIN_DT_CHR 2 | ||
| 11 | #define MY_LIN_DT_DIR 4 | ||
| 12 | #define MY_LIN_DT_BLK 6 | ||
| 13 | #define MY_LIN_DT_REG 8 | ||
| 14 | #define MY_LIN_DT_LNK 10 | ||
| 15 | #define MY_LIN_DT_SOCK 12 | ||
| 16 | #define MY_LIN_DT_WHT 14 | ||
| 17 | |||
| 6 | #define MY_LIN_S_IFMT 00170000 | 18 | #define MY_LIN_S_IFMT 00170000 |
| 7 | #define MY_LIN_S_IFSOCK 0140000 | 19 | #define MY_LIN_S_IFSOCK 0140000 |
| 8 | #define MY_LIN_S_IFLNK 0120000 | 20 | #define MY_LIN_S_IFLNK 0120000 |
| @@ -39,4 +51,25 @@ | |||
| 39 | #define MY_LIN_S_IWOTH 00002 | 51 | #define MY_LIN_S_IWOTH 00002 |
| 40 | #define MY_LIN_S_IXOTH 00001 | 52 | #define MY_LIN_S_IXOTH 00001 |
| 41 | 53 | ||
| 54 | /* | ||
| 55 | // major/minor encoding for makedev(): MMMMMmmmmmmMMMmm: | ||
| 56 | |||
| 57 | inline UInt32 MY_dev_major(UInt64 dev) | ||
| 58 | { | ||
| 59 | return ((UInt32)(dev >> 8) & (UInt32)0xfff) | ((UInt32)(dev >> 32) & ~(UInt32)0xfff); | ||
| 60 | } | ||
| 61 | |||
| 62 | inline UInt32 MY_dev_minor(UInt64 dev) | ||
| 63 | { | ||
| 64 | return ((UInt32)(dev) & 0xff) | ((UInt32)(dev >> 12) & ~0xff); | ||
| 65 | } | ||
| 66 | |||
| 67 | inline UInt64 MY_dev_makedev(UInt32 __major, UInt32 __minor) | ||
| 68 | { | ||
| 69 | return (__minor & 0xff) | ((__major & 0xfff) << 8) | ||
| 70 | | ((UInt64) (__minor & ~0xff) << 12) | ||
| 71 | | ((UInt64) (__major & ~0xfff) << 32); | ||
| 72 | } | ||
| 73 | */ | ||
| 74 | |||
| 42 | #endif | 75 | #endif |
diff --git a/CPP/Common/MyString.cpp b/CPP/Common/MyString.cpp index db202f4..bf1638e 100644 --- a/CPP/Common/MyString.cpp +++ b/CPP/Common/MyString.cpp | |||
| @@ -30,8 +30,8 @@ inline const char* MyStringGetNextCharPointer(const char *p) throw() | |||
| 30 | } | 30 | } |
| 31 | */ | 31 | */ |
| 32 | 32 | ||
| 33 | #define MY_STRING_NEW_char(_size_) MY_STRING_NEW(char, _size_) | 33 | #define MY_STRING_NEW_char(_size_) MY_STRING_NEW(char, (_size_)) |
| 34 | #define MY_STRING_NEW_wchar_t(_size_) MY_STRING_NEW(wchar_t, _size_) | 34 | #define MY_STRING_NEW_wchar_t(_size_) MY_STRING_NEW(wchar_t, (_size_)) |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | int FindCharPosInString(const char *s, char c) throw() | 37 | int FindCharPosInString(const char *s, char c) throw() |
| @@ -190,8 +190,8 @@ bool IsString1PrefixedByString2(const char *s1, const char *s2) throw() | |||
| 190 | { | 190 | { |
| 191 | for (;;) | 191 | for (;;) |
| 192 | { | 192 | { |
| 193 | unsigned char c2 = (unsigned char)*s2++; if (c2 == 0) return true; | 193 | const unsigned char c2 = (unsigned char)*s2++; if (c2 == 0) return true; |
| 194 | unsigned char c1 = (unsigned char)*s1++; if (c1 != c2) return false; | 194 | const unsigned char c1 = (unsigned char)*s1++; if (c1 != c2) return false; |
| 195 | } | 195 | } |
| 196 | } | 196 | } |
| 197 | 197 | ||
| @@ -199,8 +199,8 @@ bool StringsAreEqualNoCase(const wchar_t *s1, const wchar_t *s2) throw() | |||
| 199 | { | 199 | { |
| 200 | for (;;) | 200 | for (;;) |
| 201 | { | 201 | { |
| 202 | wchar_t c1 = *s1++; | 202 | const wchar_t c1 = *s1++; |
| 203 | wchar_t c2 = *s2++; | 203 | const wchar_t c2 = *s2++; |
| 204 | if (c1 != c2 && MyCharUpper(c1) != MyCharUpper(c2)) return false; | 204 | if (c1 != c2 && MyCharUpper(c1) != MyCharUpper(c2)) return false; |
| 205 | if (c1 == 0) return true; | 205 | if (c1 == 0) return true; |
| 206 | } | 206 | } |
| @@ -213,10 +213,10 @@ bool AString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw() | |||
| 213 | const char *s1 = _chars; | 213 | const char *s1 = _chars; |
| 214 | for (;;) | 214 | for (;;) |
| 215 | { | 215 | { |
| 216 | char c2 = *s++; | 216 | const char c2 = *s++; |
| 217 | if (c2 == 0) | 217 | if (c2 == 0) |
| 218 | return true; | 218 | return true; |
| 219 | char c1 = *s1++; | 219 | const char c1 = *s1++; |
| 220 | if (MyCharLower_Ascii(c1) != | 220 | if (MyCharLower_Ascii(c1) != |
| 221 | MyCharLower_Ascii(c2)) | 221 | MyCharLower_Ascii(c2)) |
| 222 | return false; | 222 | return false; |
| @@ -228,10 +228,10 @@ bool UString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw() | |||
| 228 | const wchar_t *s1 = _chars; | 228 | const wchar_t *s1 = _chars; |
| 229 | for (;;) | 229 | for (;;) |
| 230 | { | 230 | { |
| 231 | char c2 = *s++; | 231 | const char c2 = *s++; |
| 232 | if (c2 == 0) | 232 | if (c2 == 0) |
| 233 | return true; | 233 | return true; |
| 234 | wchar_t c1 = *s1++; | 234 | const wchar_t c1 = *s1++; |
| 235 | if (MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2)) | 235 | if (MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2)) |
| 236 | return false; | 236 | return false; |
| 237 | } | 237 | } |
| @@ -241,7 +241,7 @@ bool StringsAreEqual_Ascii(const char *u, const char *a) throw() | |||
| 241 | { | 241 | { |
| 242 | for (;;) | 242 | for (;;) |
| 243 | { | 243 | { |
| 244 | char c = *a; | 244 | const char c = *a; |
| 245 | if (c != *u) | 245 | if (c != *u) |
| 246 | return false; | 246 | return false; |
| 247 | if (c == 0) | 247 | if (c == 0) |
| @@ -255,7 +255,7 @@ bool StringsAreEqual_Ascii(const wchar_t *u, const char *a) throw() | |||
| 255 | { | 255 | { |
| 256 | for (;;) | 256 | for (;;) |
| 257 | { | 257 | { |
| 258 | unsigned char c = (unsigned char)*a; | 258 | const unsigned char c = (unsigned char)*a; |
| 259 | if (c != *u) | 259 | if (c != *u) |
| 260 | return false; | 260 | return false; |
| 261 | if (c == 0) | 261 | if (c == 0) |
| @@ -269,8 +269,8 @@ bool StringsAreEqualNoCase_Ascii(const char *s1, const char *s2) throw() | |||
| 269 | { | 269 | { |
| 270 | for (;;) | 270 | for (;;) |
| 271 | { | 271 | { |
| 272 | char c1 = *s1++; | 272 | const char c1 = *s1++; |
| 273 | char c2 = *s2++; | 273 | const char c2 = *s2++; |
| 274 | if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2)) | 274 | if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2)) |
| 275 | return false; | 275 | return false; |
| 276 | if (c1 == 0) | 276 | if (c1 == 0) |
| @@ -282,8 +282,8 @@ bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2) throw() | |||
| 282 | { | 282 | { |
| 283 | for (;;) | 283 | for (;;) |
| 284 | { | 284 | { |
| 285 | wchar_t c1 = *s1++; | 285 | const wchar_t c1 = *s1++; |
| 286 | wchar_t c2 = *s2++; | 286 | const wchar_t c2 = *s2++; |
| 287 | if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2)) | 287 | if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2)) |
| 288 | return false; | 288 | return false; |
| 289 | if (c1 == 0) | 289 | if (c1 == 0) |
| @@ -295,8 +295,8 @@ bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2) throw() | |||
| 295 | { | 295 | { |
| 296 | for (;;) | 296 | for (;;) |
| 297 | { | 297 | { |
| 298 | wchar_t c1 = *s1++; | 298 | const wchar_t c1 = *s1++; |
| 299 | char c2 = *s2++; | 299 | const char c2 = *s2++; |
| 300 | if (c1 != (unsigned char)c2 && (c1 > 0x7F || MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2))) | 300 | if (c1 != (unsigned char)c2 && (c1 > 0x7F || MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2))) |
| 301 | return false; | 301 | return false; |
| 302 | if (c1 == 0) | 302 | if (c1 == 0) |
| @@ -308,8 +308,8 @@ bool IsString1PrefixedByString2(const wchar_t *s1, const wchar_t *s2) throw() | |||
| 308 | { | 308 | { |
| 309 | for (;;) | 309 | for (;;) |
| 310 | { | 310 | { |
| 311 | wchar_t c2 = *s2++; if (c2 == 0) return true; | 311 | const wchar_t c2 = *s2++; if (c2 == 0) return true; |
| 312 | wchar_t c1 = *s1++; if (c1 != c2) return false; | 312 | const wchar_t c1 = *s1++; if (c1 != c2) return false; |
| 313 | } | 313 | } |
| 314 | } | 314 | } |
| 315 | 315 | ||
| @@ -317,8 +317,8 @@ bool IsString1PrefixedByString2(const wchar_t *s1, const char *s2) throw() | |||
| 317 | { | 317 | { |
| 318 | for (;;) | 318 | for (;;) |
| 319 | { | 319 | { |
| 320 | unsigned char c2 = (unsigned char)(*s2++); if (c2 == 0) return true; | 320 | const unsigned char c2 = (unsigned char)(*s2++); if (c2 == 0) return true; |
| 321 | wchar_t c1 = *s1++; if (c1 != c2) return false; | 321 | const wchar_t c1 = *s1++; if (c1 != c2) return false; |
| 322 | } | 322 | } |
| 323 | } | 323 | } |
| 324 | 324 | ||
| @@ -326,8 +326,8 @@ bool IsString1PrefixedByString2_NoCase_Ascii(const char *s1, const char *s2) thr | |||
| 326 | { | 326 | { |
| 327 | for (;;) | 327 | for (;;) |
| 328 | { | 328 | { |
| 329 | char c2 = *s2++; if (c2 == 0) return true; | 329 | const char c2 = *s2++; if (c2 == 0) return true; |
| 330 | char c1 = *s1++; | 330 | const char c1 = *s1++; |
| 331 | if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2)) | 331 | if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2)) |
| 332 | return false; | 332 | return false; |
| 333 | } | 333 | } |
| @@ -337,8 +337,8 @@ bool IsString1PrefixedByString2_NoCase_Ascii(const wchar_t *s1, const char *s2) | |||
| 337 | { | 337 | { |
| 338 | for (;;) | 338 | for (;;) |
| 339 | { | 339 | { |
| 340 | char c2 = *s2++; if (c2 == 0) return true; | 340 | const char c2 = *s2++; if (c2 == 0) return true; |
| 341 | wchar_t c1 = *s1++; | 341 | const wchar_t c1 = *s1++; |
| 342 | if (c1 != (unsigned char)c2 && MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2)) | 342 | if (c1 != (unsigned char)c2 && MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2)) |
| 343 | return false; | 343 | return false; |
| 344 | } | 344 | } |
| @@ -348,8 +348,8 @@ bool IsString1PrefixedByString2_NoCase(const wchar_t *s1, const wchar_t *s2) thr | |||
| 348 | { | 348 | { |
| 349 | for (;;) | 349 | for (;;) |
| 350 | { | 350 | { |
| 351 | wchar_t c2 = *s2++; if (c2 == 0) return true; | 351 | const wchar_t c2 = *s2++; if (c2 == 0) return true; |
| 352 | wchar_t c1 = *s1++; | 352 | const wchar_t c1 = *s1++; |
| 353 | if (c1 != c2 && MyCharUpper(c1) != MyCharUpper(c2)) | 353 | if (c1 != c2 && MyCharUpper(c1) != MyCharUpper(c2)) |
| 354 | return false; | 354 | return false; |
| 355 | } | 355 | } |
| @@ -360,12 +360,12 @@ int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2) throw() | |||
| 360 | { | 360 | { |
| 361 | for (;;) | 361 | for (;;) |
| 362 | { | 362 | { |
| 363 | wchar_t c1 = *s1++; | 363 | const wchar_t c1 = *s1++; |
| 364 | wchar_t c2 = *s2++; | 364 | const wchar_t c2 = *s2++; |
| 365 | if (c1 != c2) | 365 | if (c1 != c2) |
| 366 | { | 366 | { |
| 367 | wchar_t u1 = MyCharUpper(c1); | 367 | const wchar_t u1 = MyCharUpper(c1); |
| 368 | wchar_t u2 = MyCharUpper(c2); | 368 | const wchar_t u2 = MyCharUpper(c2); |
| 369 | if (u1 < u2) return -1; | 369 | if (u1 < u2) return -1; |
| 370 | if (u1 > u2) return 1; | 370 | if (u1 > u2) return 1; |
| 371 | } | 371 | } |
| @@ -401,14 +401,13 @@ void AString::InsertSpace(unsigned &index, unsigned size) | |||
| 401 | MoveItems(index + size, index); | 401 | MoveItems(index + size, index); |
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | #define k_Alloc_Len_Limit 0x40000000 | 404 | #define k_Alloc_Len_Limit (0x40000000 - 2) |
| 405 | 405 | ||
| 406 | void AString::ReAlloc(unsigned newLimit) | 406 | void AString::ReAlloc(unsigned newLimit) |
| 407 | { | 407 | { |
| 408 | if (newLimit < _len || newLimit >= k_Alloc_Len_Limit) throw 20130220; | 408 | // MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, (size_t)_len + 1); |
| 409 | // MY_STRING_REALLOC(_chars, char, newLimit + 1, _len + 1); | 409 | char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1); |
| 410 | char *newBuf = MY_STRING_NEW_char(newLimit + 1); | 410 | memcpy(newBuf, _chars, (size_t)_len + 1); |
| 411 | memcpy(newBuf, _chars, (size_t)(_len + 1)); | ||
| 412 | MY_STRING_DELETE(_chars); | 411 | MY_STRING_DELETE(_chars); |
| 413 | _chars = newBuf; | 412 | _chars = newBuf; |
| 414 | _limit = newLimit; | 413 | _limit = newLimit; |
| @@ -416,9 +415,9 @@ void AString::ReAlloc(unsigned newLimit) | |||
| 416 | 415 | ||
| 417 | void AString::ReAlloc2(unsigned newLimit) | 416 | void AString::ReAlloc2(unsigned newLimit) |
| 418 | { | 417 | { |
| 419 | if (newLimit >= k_Alloc_Len_Limit) throw 20130220; | 418 | if (newLimit > k_Alloc_Len_Limit) throw 20130220; |
| 420 | // MY_STRING_REALLOC(_chars, char, newLimit + 1, 0); | 419 | // MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, 0); |
| 421 | char *newBuf = MY_STRING_NEW_char(newLimit + 1); | 420 | char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1); |
| 422 | newBuf[0] = 0; | 421 | newBuf[0] = 0; |
| 423 | MY_STRING_DELETE(_chars); | 422 | MY_STRING_DELETE(_chars); |
| 424 | _chars = newBuf; | 423 | _chars = newBuf; |
| @@ -427,8 +426,8 @@ void AString::ReAlloc2(unsigned newLimit) | |||
| 427 | 426 | ||
| 428 | void AString::SetStartLen(unsigned len) | 427 | void AString::SetStartLen(unsigned len) |
| 429 | { | 428 | { |
| 430 | _chars = 0; | 429 | _chars = NULL; |
| 431 | _chars = MY_STRING_NEW_char(len + 1); | 430 | _chars = MY_STRING_NEW_char((size_t)len + 1); |
| 432 | _len = len; | 431 | _len = len; |
| 433 | _limit = len; | 432 | _limit = len; |
| 434 | } | 433 | } |
| @@ -439,20 +438,30 @@ void AString::Grow_1() | |||
| 439 | next += next / 2; | 438 | next += next / 2; |
| 440 | next += 16; | 439 | next += 16; |
| 441 | next &= ~(unsigned)15; | 440 | next &= ~(unsigned)15; |
| 442 | ReAlloc(next - 1); | 441 | next--; |
| 442 | if (next < _len || next > k_Alloc_Len_Limit) | ||
| 443 | next = k_Alloc_Len_Limit; | ||
| 444 | if (next <= _len) | ||
| 445 | throw 20130220; | ||
| 446 | ReAlloc(next); | ||
| 447 | // Grow(1); | ||
| 443 | } | 448 | } |
| 444 | 449 | ||
| 445 | void AString::Grow(unsigned n) | 450 | void AString::Grow(unsigned n) |
| 446 | { | 451 | { |
| 447 | unsigned freeSize = _limit - _len; | 452 | const unsigned freeSize = _limit - _len; |
| 448 | if (n <= freeSize) | 453 | if (n <= freeSize) |
| 449 | return; | 454 | return; |
| 450 | |||
| 451 | unsigned next = _len + n; | 455 | unsigned next = _len + n; |
| 452 | next += next / 2; | 456 | next += next / 2; |
| 453 | next += 16; | 457 | next += 16; |
| 454 | next &= ~(unsigned)15; | 458 | next &= ~(unsigned)15; |
| 455 | ReAlloc(next - 1); | 459 | next--; |
| 460 | if (next < _len || next > k_Alloc_Len_Limit) | ||
| 461 | next = k_Alloc_Len_Limit; | ||
| 462 | if (next <= _len || next - _len < n) | ||
| 463 | throw 20130220; | ||
| 464 | ReAlloc(next); | ||
| 456 | } | 465 | } |
| 457 | 466 | ||
| 458 | AString::AString(unsigned num, const char *s) | 467 | AString::AString(unsigned num, const char *s) |
| @@ -500,7 +509,7 @@ static const unsigned kStartStringCapacity = 4; | |||
| 500 | 509 | ||
| 501 | AString::AString() | 510 | AString::AString() |
| 502 | { | 511 | { |
| 503 | _chars = 0; | 512 | _chars = NULL; |
| 504 | _chars = MY_STRING_NEW_char(kStartStringCapacity); | 513 | _chars = MY_STRING_NEW_char(kStartStringCapacity); |
| 505 | _len = 0; | 514 | _len = 0; |
| 506 | _limit = kStartStringCapacity - 1; | 515 | _limit = kStartStringCapacity - 1; |
| @@ -548,7 +557,7 @@ AString &AString::operator=(const char *s) | |||
| 548 | unsigned len = MyStringLen(s); | 557 | unsigned len = MyStringLen(s); |
| 549 | if (len > _limit) | 558 | if (len > _limit) |
| 550 | { | 559 | { |
| 551 | char *newBuf = MY_STRING_NEW_char(len + 1); | 560 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
| 552 | MY_STRING_DELETE(_chars); | 561 | MY_STRING_DELETE(_chars); |
| 553 | _chars = newBuf; | 562 | _chars = newBuf; |
| 554 | _limit = len; | 563 | _limit = len; |
| @@ -565,7 +574,7 @@ AString &AString::operator=(const AString &s) | |||
| 565 | unsigned len = s._len; | 574 | unsigned len = s._len; |
| 566 | if (len > _limit) | 575 | if (len > _limit) |
| 567 | { | 576 | { |
| 568 | char *newBuf = MY_STRING_NEW_char(len + 1); | 577 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
| 569 | MY_STRING_DELETE(_chars); | 578 | MY_STRING_DELETE(_chars); |
| 570 | _chars = newBuf; | 579 | _chars = newBuf; |
| 571 | _limit = len; | 580 | _limit = len; |
| @@ -590,7 +599,7 @@ void AString::SetFromWStr_if_Ascii(const wchar_t *s) | |||
| 590 | } | 599 | } |
| 591 | if (len > _limit) | 600 | if (len > _limit) |
| 592 | { | 601 | { |
| 593 | char *newBuf = MY_STRING_NEW_char(len + 1); | 602 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
| 594 | MY_STRING_DELETE(_chars); | 603 | MY_STRING_DELETE(_chars); |
| 595 | _chars = newBuf; | 604 | _chars = newBuf; |
| 596 | _limit = len; | 605 | _limit = len; |
| @@ -614,7 +623,7 @@ void AString::SetFromBstr_if_Ascii(BSTR s) | |||
| 614 | } | 623 | } |
| 615 | if (len > _limit) | 624 | if (len > _limit) |
| 616 | { | 625 | { |
| 617 | char *newBuf = MY_STRING_NEW_char(len + 1); | 626 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
| 618 | MY_STRING_DELETE(_chars); | 627 | MY_STRING_DELETE(_chars); |
| 619 | _chars = newBuf; | 628 | _chars = newBuf; |
| 620 | _limit = len; | 629 | _limit = len; |
| @@ -631,6 +640,7 @@ void AString::SetFromBstr_if_Ascii(BSTR s) | |||
| 631 | void AString::Add_Space() { operator+=(' '); } | 640 | void AString::Add_Space() { operator+=(' '); } |
| 632 | void AString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } | 641 | void AString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); } |
| 633 | void AString::Add_LF() { operator+=('\n'); } | 642 | void AString::Add_LF() { operator+=('\n'); } |
| 643 | void AString::Add_Slash() { operator+=('/'); } | ||
| 634 | 644 | ||
| 635 | AString &AString::operator+=(const char *s) | 645 | AString &AString::operator+=(const char *s) |
| 636 | { | 646 | { |
| @@ -667,11 +677,23 @@ void UString::Add_UInt64(UInt64 v) | |||
| 667 | _len = (unsigned)(ConvertUInt64ToString(v, _chars + _len) - _chars); | 677 | _len = (unsigned)(ConvertUInt64ToString(v, _chars + _len) - _chars); |
| 668 | } | 678 | } |
| 669 | 679 | ||
| 680 | void AString::AddFrom(const char *s, unsigned len) // no check | ||
| 681 | { | ||
| 682 | if (len != 0) | ||
| 683 | { | ||
| 684 | Grow(len); | ||
| 685 | memcpy(_chars + _len, s, len); | ||
| 686 | len += _len; | ||
| 687 | _chars[len] = 0; | ||
| 688 | _len = len; | ||
| 689 | } | ||
| 690 | } | ||
| 691 | |||
| 670 | void AString::SetFrom(const char *s, unsigned len) // no check | 692 | void AString::SetFrom(const char *s, unsigned len) // no check |
| 671 | { | 693 | { |
| 672 | if (len > _limit) | 694 | if (len > _limit) |
| 673 | { | 695 | { |
| 674 | char *newBuf = MY_STRING_NEW_char(len + 1); | 696 | char *newBuf = MY_STRING_NEW_char((size_t)len + 1); |
| 675 | MY_STRING_DELETE(_chars); | 697 | MY_STRING_DELETE(_chars); |
| 676 | _chars = newBuf; | 698 | _chars = newBuf; |
| 677 | _limit = len; | 699 | _limit = len; |
| @@ -976,9 +998,8 @@ void UString::InsertSpace(unsigned index, unsigned size) | |||
| 976 | 998 | ||
| 977 | void UString::ReAlloc(unsigned newLimit) | 999 | void UString::ReAlloc(unsigned newLimit) |
| 978 | { | 1000 | { |
| 979 | if (newLimit < _len || newLimit >= k_Alloc_Len_Limit) throw 20130221; | 1001 | // MY_STRING_REALLOC(_chars, wchar_t, (size_t)newLimit + 1, (size_t)_len + 1); |
| 980 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, _len + 1); | 1002 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1); |
| 981 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(newLimit + 1); | ||
| 982 | wmemcpy(newBuf, _chars, _len + 1); | 1003 | wmemcpy(newBuf, _chars, _len + 1); |
| 983 | MY_STRING_DELETE(_chars); | 1004 | MY_STRING_DELETE(_chars); |
| 984 | _chars = newBuf; | 1005 | _chars = newBuf; |
| @@ -987,9 +1008,9 @@ void UString::ReAlloc(unsigned newLimit) | |||
| 987 | 1008 | ||
| 988 | void UString::ReAlloc2(unsigned newLimit) | 1009 | void UString::ReAlloc2(unsigned newLimit) |
| 989 | { | 1010 | { |
| 990 | if (newLimit >= k_Alloc_Len_Limit) throw 20130221; | 1011 | if (newLimit > k_Alloc_Len_Limit) throw 20130221; |
| 991 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); | 1012 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); |
| 992 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(newLimit + 1); | 1013 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1); |
| 993 | newBuf[0] = 0; | 1014 | newBuf[0] = 0; |
| 994 | MY_STRING_DELETE(_chars); | 1015 | MY_STRING_DELETE(_chars); |
| 995 | _chars = newBuf; | 1016 | _chars = newBuf; |
| @@ -999,7 +1020,7 @@ void UString::ReAlloc2(unsigned newLimit) | |||
| 999 | void UString::SetStartLen(unsigned len) | 1020 | void UString::SetStartLen(unsigned len) |
| 1000 | { | 1021 | { |
| 1001 | _chars = 0; | 1022 | _chars = 0; |
| 1002 | _chars = MY_STRING_NEW_wchar_t(len + 1); | 1023 | _chars = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1003 | _len = len; | 1024 | _len = len; |
| 1004 | _limit = len; | 1025 | _limit = len; |
| 1005 | } | 1026 | } |
| @@ -1010,19 +1031,28 @@ void UString::Grow_1() | |||
| 1010 | next += next / 2; | 1031 | next += next / 2; |
| 1011 | next += 16; | 1032 | next += 16; |
| 1012 | next &= ~(unsigned)15; | 1033 | next &= ~(unsigned)15; |
| 1013 | ReAlloc(next - 1); | 1034 | next--; |
| 1035 | if (next < _len || next > k_Alloc_Len_Limit) | ||
| 1036 | next = k_Alloc_Len_Limit; | ||
| 1037 | if (next <= _len) | ||
| 1038 | throw 20130220; | ||
| 1039 | ReAlloc(next); | ||
| 1014 | } | 1040 | } |
| 1015 | 1041 | ||
| 1016 | void UString::Grow(unsigned n) | 1042 | void UString::Grow(unsigned n) |
| 1017 | { | 1043 | { |
| 1018 | unsigned freeSize = _limit - _len; | 1044 | const unsigned freeSize = _limit - _len; |
| 1019 | if (n <= freeSize) | 1045 | if (n <= freeSize) |
| 1020 | return; | 1046 | return; |
| 1021 | |||
| 1022 | unsigned next = _len + n; | 1047 | unsigned next = _len + n; |
| 1023 | next += next / 2; | 1048 | next += next / 2; |
| 1024 | next += 16; | 1049 | next += 16; |
| 1025 | next &= ~(unsigned)15; | 1050 | next &= ~(unsigned)15; |
| 1051 | next--; | ||
| 1052 | if (next < _len || next > k_Alloc_Len_Limit) | ||
| 1053 | next = k_Alloc_Len_Limit; | ||
| 1054 | if (next <= _len || next - _len < n) | ||
| 1055 | throw 20130220; | ||
| 1026 | ReAlloc(next - 1); | 1056 | ReAlloc(next - 1); |
| 1027 | } | 1057 | } |
| 1028 | 1058 | ||
| @@ -1149,7 +1179,7 @@ UString &UString::operator=(const wchar_t *s) | |||
| 1149 | unsigned len = MyStringLen(s); | 1179 | unsigned len = MyStringLen(s); |
| 1150 | if (len > _limit) | 1180 | if (len > _limit) |
| 1151 | { | 1181 | { |
| 1152 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1); | 1182 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1153 | MY_STRING_DELETE(_chars); | 1183 | MY_STRING_DELETE(_chars); |
| 1154 | _chars = newBuf; | 1184 | _chars = newBuf; |
| 1155 | _limit = len; | 1185 | _limit = len; |
| @@ -1166,7 +1196,7 @@ UString &UString::operator=(const UString &s) | |||
| 1166 | unsigned len = s._len; | 1196 | unsigned len = s._len; |
| 1167 | if (len > _limit) | 1197 | if (len > _limit) |
| 1168 | { | 1198 | { |
| 1169 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1); | 1199 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1170 | MY_STRING_DELETE(_chars); | 1200 | MY_STRING_DELETE(_chars); |
| 1171 | _chars = newBuf; | 1201 | _chars = newBuf; |
| 1172 | _limit = len; | 1202 | _limit = len; |
| @@ -1180,7 +1210,7 @@ void UString::SetFrom(const wchar_t *s, unsigned len) // no check | |||
| 1180 | { | 1210 | { |
| 1181 | if (len > _limit) | 1211 | if (len > _limit) |
| 1182 | { | 1212 | { |
| 1183 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1); | 1213 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1184 | MY_STRING_DELETE(_chars); | 1214 | MY_STRING_DELETE(_chars); |
| 1185 | _chars = newBuf; | 1215 | _chars = newBuf; |
| 1186 | _limit = len; | 1216 | _limit = len; |
| @@ -1218,7 +1248,7 @@ void UString::SetFromBstr(LPCOLESTR s) | |||
| 1218 | 1248 | ||
| 1219 | if (len > _limit) | 1249 | if (len > _limit) |
| 1220 | { | 1250 | { |
| 1221 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1); | 1251 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1222 | MY_STRING_DELETE(_chars); | 1252 | MY_STRING_DELETE(_chars); |
| 1223 | _chars = newBuf; | 1253 | _chars = newBuf; |
| 1224 | _limit = len; | 1254 | _limit = len; |
| @@ -1258,7 +1288,7 @@ UString &UString::operator=(const char *s) | |||
| 1258 | unsigned len = MyStringLen(s); | 1288 | unsigned len = MyStringLen(s); |
| 1259 | if (len > _limit) | 1289 | if (len > _limit) |
| 1260 | { | 1290 | { |
| 1261 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1); | 1291 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1262 | MY_STRING_DELETE(_chars); | 1292 | MY_STRING_DELETE(_chars); |
| 1263 | _chars = newBuf; | 1293 | _chars = newBuf; |
| 1264 | _limit = len; | 1294 | _limit = len; |
| @@ -1566,15 +1596,24 @@ void UString::DeleteFrontal(unsigned num) throw() | |||
| 1566 | 1596 | ||
| 1567 | void UString2::ReAlloc2(unsigned newLimit) | 1597 | void UString2::ReAlloc2(unsigned newLimit) |
| 1568 | { | 1598 | { |
| 1569 | if (newLimit >= k_Alloc_Len_Limit) throw 20130221; | 1599 | // wrong (_len) is allowed after this function |
| 1600 | if (newLimit > k_Alloc_Len_Limit) throw 20130221; | ||
| 1570 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); | 1601 | // MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0); |
| 1571 | _chars = MY_STRING_NEW_wchar_t(newLimit + 1); | 1602 | if (_chars) |
| 1603 | { | ||
| 1604 | MY_STRING_DELETE(_chars); | ||
| 1605 | _chars = NULL; | ||
| 1606 | // _len = 0; | ||
| 1607 | } | ||
| 1608 | _chars = MY_STRING_NEW_wchar_t((size_t)newLimit + 1); | ||
| 1609 | _chars[0] = 0; | ||
| 1610 | // _len = newLimit; | ||
| 1572 | } | 1611 | } |
| 1573 | 1612 | ||
| 1574 | void UString2::SetStartLen(unsigned len) | 1613 | void UString2::SetStartLen(unsigned len) |
| 1575 | { | 1614 | { |
| 1576 | _chars = 0; | 1615 | _chars = NULL; |
| 1577 | _chars = MY_STRING_NEW_wchar_t(len + 1); | 1616 | _chars = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1578 | _len = len; | 1617 | _len = len; |
| 1579 | } | 1618 | } |
| 1580 | 1619 | ||
| @@ -1591,7 +1630,7 @@ UString2::UString2(wchar_t c) | |||
| 1591 | 1630 | ||
| 1592 | UString2::UString2(const wchar_t *s) | 1631 | UString2::UString2(const wchar_t *s) |
| 1593 | { | 1632 | { |
| 1594 | unsigned len = MyStringLen(s); | 1633 | const unsigned len = MyStringLen(s); |
| 1595 | SetStartLen(len); | 1634 | SetStartLen(len); |
| 1596 | wmemcpy(_chars, s, len + 1); | 1635 | wmemcpy(_chars, s, len + 1); |
| 1597 | } | 1636 | } |
| @@ -1628,7 +1667,7 @@ UString2 &UString2::operator=(const wchar_t *s) | |||
| 1628 | unsigned len = MyStringLen(s); | 1667 | unsigned len = MyStringLen(s); |
| 1629 | if (len > _len) | 1668 | if (len > _len) |
| 1630 | { | 1669 | { |
| 1631 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1); | 1670 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1632 | if (_chars) | 1671 | if (_chars) |
| 1633 | MY_STRING_DELETE(_chars); | 1672 | MY_STRING_DELETE(_chars); |
| 1634 | _chars = newBuf; | 1673 | _chars = newBuf; |
| @@ -1643,7 +1682,7 @@ void UString2::SetFromAscii(const char *s) | |||
| 1643 | unsigned len = MyStringLen(s); | 1682 | unsigned len = MyStringLen(s); |
| 1644 | if (len > _len) | 1683 | if (len > _len) |
| 1645 | { | 1684 | { |
| 1646 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1); | 1685 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1647 | if (_chars) | 1686 | if (_chars) |
| 1648 | MY_STRING_DELETE(_chars); | 1687 | MY_STRING_DELETE(_chars); |
| 1649 | _chars = newBuf; | 1688 | _chars = newBuf; |
| @@ -1662,7 +1701,7 @@ UString2 &UString2::operator=(const UString2 &s) | |||
| 1662 | unsigned len = s._len; | 1701 | unsigned len = s._len; |
| 1663 | if (len > _len) | 1702 | if (len > _len) |
| 1664 | { | 1703 | { |
| 1665 | wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1); | 1704 | wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1); |
| 1666 | if (_chars) | 1705 | if (_chars) |
| 1667 | MY_STRING_DELETE(_chars); | 1706 | MY_STRING_DELETE(_chars); |
| 1668 | _chars = newBuf; | 1707 | _chars = newBuf; |
diff --git a/CPP/Common/MyString.h b/CPP/Common/MyString.h index aa3c301..c777c8c 100644 --- a/CPP/Common/MyString.h +++ b/CPP/Common/MyString.h | |||
| @@ -378,6 +378,7 @@ public: | |||
| 378 | void Add_Space_if_NotEmpty(); | 378 | void Add_Space_if_NotEmpty(); |
| 379 | void Add_OptSpaced(const char *s); | 379 | void Add_OptSpaced(const char *s); |
| 380 | void Add_LF(); | 380 | void Add_LF(); |
| 381 | void Add_Slash(); | ||
| 381 | void Add_PathSepar() { operator+=(CHAR_PATH_SEPARATOR); } | 382 | void Add_PathSepar() { operator+=(CHAR_PATH_SEPARATOR); } |
| 382 | 383 | ||
| 383 | AString &operator+=(const char *s); | 384 | AString &operator+=(const char *s); |
| @@ -386,12 +387,12 @@ public: | |||
| 386 | void Add_UInt32(UInt32 v); | 387 | void Add_UInt32(UInt32 v); |
| 387 | void Add_UInt64(UInt64 v); | 388 | void Add_UInt64(UInt64 v); |
| 388 | 389 | ||
| 390 | void AddFrom(const char *s, unsigned len); // no check | ||
| 389 | void SetFrom(const char *s, unsigned len); // no check | 391 | void SetFrom(const char *s, unsigned len); // no check |
| 390 | void SetFrom_CalcLen(const char *s, unsigned len); | 392 | void SetFrom_CalcLen(const char *s, unsigned len); |
| 391 | 393 | ||
| 392 | AString Mid(unsigned startIndex, unsigned count) const { return AString(count, _chars + startIndex); } | 394 | AString Mid(unsigned startIndex, unsigned count) const { return AString(count, _chars + startIndex); } |
| 393 | AString Left(unsigned count) const { return AString(count, *this); } | 395 | AString Left(unsigned count) const { return AString(count, *this); } |
| 394 | |||
| 395 | // void MakeUpper() { MyStringUpper(_chars); } | 396 | // void MakeUpper() { MyStringUpper(_chars); } |
| 396 | // void MakeLower() { MyStringLower(_chars); } | 397 | // void MakeLower() { MyStringLower(_chars); } |
| 397 | void MakeLower_Ascii() { MyStringLower_Ascii(_chars); } | 398 | void MakeLower_Ascii() { MyStringLower_Ascii(_chars); } |
diff --git a/CPP/Common/MyVector.h b/CPP/Common/MyVector.h index c851234..3417a17 100644 --- a/CPP/Common/MyVector.h +++ b/CPP/Common/MyVector.h | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | #include <string.h> | 6 | #include <string.h> |
| 7 | 7 | ||
| 8 | const unsigned k_VectorSizeMax = ((unsigned)1 << 31) - 1; | ||
| 9 | |||
| 8 | template <class T> | 10 | template <class T> |
| 9 | class CRecordVector | 11 | class CRecordVector |
| 10 | { | 12 | { |
| @@ -17,31 +19,41 @@ class CRecordVector | |||
| 17 | memmove(_items + destIndex, _items + srcIndex, (size_t)(_size - srcIndex) * sizeof(T)); | 19 | memmove(_items + destIndex, _items + srcIndex, (size_t)(_size - srcIndex) * sizeof(T)); |
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | void ReserveOnePosition() | 22 | void ReAllocForNewCapacity(const unsigned newCapacity) |
| 21 | { | 23 | { |
| 22 | if (_size == _capacity) | 24 | T *p; |
| 23 | { | 25 | MY_ARRAY_NEW(p, T, newCapacity); |
| 24 | unsigned newCapacity = _capacity + (_capacity >> 2) + 1; | 26 | // p = new T[newCapacity]; |
| 25 | T *p; | 27 | if (_size != 0) |
| 26 | MY_ARRAY_NEW(p, T, newCapacity); | 28 | memcpy(p, _items, (size_t)_size * sizeof(T)); |
| 27 | // p = new T[newCapacity]; | 29 | delete []_items; |
| 28 | if (_size != 0) | 30 | _items = p; |
| 29 | memcpy(p, _items, (size_t)_size * sizeof(T)); | 31 | _capacity = newCapacity; |
| 30 | delete []_items; | ||
| 31 | _items = p; | ||
| 32 | _capacity = newCapacity; | ||
| 33 | } | ||
| 34 | } | 32 | } |
| 35 | 33 | ||
| 36 | public: | 34 | public: |
| 37 | 35 | ||
| 36 | void ReserveOnePosition() | ||
| 37 | { | ||
| 38 | if (_size != _capacity) | ||
| 39 | return; | ||
| 40 | if (_capacity >= k_VectorSizeMax) | ||
| 41 | throw 2021; | ||
| 42 | const unsigned rem = k_VectorSizeMax - _capacity; | ||
| 43 | unsigned add = (_capacity >> 2) + 1; | ||
| 44 | if (add > rem) | ||
| 45 | add = rem; | ||
| 46 | ReAllocForNewCapacity(_capacity + add); | ||
| 47 | } | ||
| 48 | |||
| 38 | CRecordVector(): _items(NULL), _size(0), _capacity(0) {} | 49 | CRecordVector(): _items(NULL), _size(0), _capacity(0) {} |
| 39 | 50 | ||
| 40 | CRecordVector(const CRecordVector &v): _items(0), _size(0), _capacity(0) | 51 | CRecordVector(const CRecordVector &v): _items(NULL), _size(0), _capacity(0) |
| 41 | { | 52 | { |
| 42 | unsigned size = v.Size(); | 53 | const unsigned size = v.Size(); |
| 43 | if (size != 0) | 54 | if (size != 0) |
| 44 | { | 55 | { |
| 56 | // MY_ARRAY_NEW(_items, T, size) | ||
| 45 | _items = new T[size]; | 57 | _items = new T[size]; |
| 46 | _size = size; | 58 | _size = size; |
| 47 | _capacity = size; | 59 | _capacity = size; |
| @@ -66,22 +78,25 @@ public: | |||
| 66 | { | 78 | { |
| 67 | if (newCapacity > _capacity) | 79 | if (newCapacity > _capacity) |
| 68 | { | 80 | { |
| 69 | T *p; | 81 | if (newCapacity > k_VectorSizeMax) |
| 70 | MY_ARRAY_NEW(p, T, newCapacity); | 82 | throw 2021; |
| 71 | // p = new T[newCapacity]; | 83 | ReAllocForNewCapacity(newCapacity); |
| 72 | if (_size != 0) | ||
| 73 | memcpy(p, _items, (size_t)_size * sizeof(T)); | ||
| 74 | delete []_items; | ||
| 75 | _items = p; | ||
| 76 | _capacity = newCapacity; | ||
| 77 | } | 84 | } |
| 78 | } | 85 | } |
| 79 | 86 | ||
| 87 | void ChangeSize_KeepData(unsigned newSize) | ||
| 88 | { | ||
| 89 | Reserve(newSize); | ||
| 90 | _size = newSize; | ||
| 91 | } | ||
| 92 | |||
| 80 | void ClearAndReserve(unsigned newCapacity) | 93 | void ClearAndReserve(unsigned newCapacity) |
| 81 | { | 94 | { |
| 82 | Clear(); | 95 | Clear(); |
| 83 | if (newCapacity > _capacity) | 96 | if (newCapacity > _capacity) |
| 84 | { | 97 | { |
| 98 | if (newCapacity > k_VectorSizeMax) | ||
| 99 | throw 2021; | ||
| 85 | delete []_items; | 100 | delete []_items; |
| 86 | _items = NULL; | 101 | _items = NULL; |
| 87 | _capacity = 0; | 102 | _capacity = 0; |
| @@ -97,22 +112,6 @@ public: | |||
| 97 | _size = newSize; | 112 | _size = newSize; |
| 98 | } | 113 | } |
| 99 | 114 | ||
| 100 | void ChangeSize_KeepData(unsigned newSize) | ||
| 101 | { | ||
| 102 | if (newSize > _capacity) | ||
| 103 | { | ||
| 104 | T *p; | ||
| 105 | MY_ARRAY_NEW(p, T, newSize) | ||
| 106 | // p = new T[newSize]; | ||
| 107 | if (_size != 0) | ||
| 108 | memcpy(p, _items, (size_t)_size * sizeof(T)); | ||
| 109 | delete []_items; | ||
| 110 | _items = p; | ||
| 111 | _capacity = newSize; | ||
| 112 | } | ||
| 113 | _size = newSize; | ||
| 114 | } | ||
| 115 | |||
| 116 | void ReserveDown() | 115 | void ReserveDown() |
| 117 | { | 116 | { |
| 118 | if (_size == _capacity) | 117 | if (_size == _capacity) |
| @@ -120,6 +119,7 @@ public: | |||
| 120 | T *p = NULL; | 119 | T *p = NULL; |
| 121 | if (_size != 0) | 120 | if (_size != 0) |
| 122 | { | 121 | { |
| 122 | // MY_ARRAY_NEW(p, T, _size) | ||
| 123 | p = new T[_size]; | 123 | p = new T[_size]; |
| 124 | memcpy(p, _items, (size_t)_size * sizeof(T)); | 124 | memcpy(p, _items, (size_t)_size * sizeof(T)); |
| 125 | } | 125 | } |
| @@ -178,7 +178,7 @@ public: | |||
| 178 | { | 178 | { |
| 179 | if (&v == this) | 179 | if (&v == this) |
| 180 | return *this; | 180 | return *this; |
| 181 | unsigned size = v.Size(); | 181 | const unsigned size = v.Size(); |
| 182 | if (size > _capacity) | 182 | if (size > _capacity) |
| 183 | { | 183 | { |
| 184 | delete []_items; | 184 | delete []_items; |
| @@ -196,24 +196,45 @@ public: | |||
| 196 | 196 | ||
| 197 | CRecordVector& operator+=(const CRecordVector &v) | 197 | CRecordVector& operator+=(const CRecordVector &v) |
| 198 | { | 198 | { |
| 199 | unsigned size = v.Size(); | 199 | const unsigned size = v.Size(); |
| 200 | Reserve(_size + size); | ||
| 201 | if (size != 0) | 200 | if (size != 0) |
| 201 | { | ||
| 202 | if (_size >= k_VectorSizeMax || size > k_VectorSizeMax - _size) | ||
| 203 | throw 2021; | ||
| 204 | const unsigned newSize = _size + size; | ||
| 205 | Reserve(newSize); | ||
| 202 | memcpy(_items + _size, v._items, (size_t)size * sizeof(T)); | 206 | memcpy(_items + _size, v._items, (size_t)size * sizeof(T)); |
| 203 | _size += size; | 207 | _size = newSize; |
| 208 | } | ||
| 204 | return *this; | 209 | return *this; |
| 205 | } | 210 | } |
| 206 | 211 | ||
| 207 | unsigned Add(const T item) | 212 | unsigned Add(const T item) |
| 208 | { | 213 | { |
| 209 | ReserveOnePosition(); | 214 | ReserveOnePosition(); |
| 210 | _items[_size] = item; | 215 | const unsigned size = _size; |
| 211 | return _size++; | 216 | _size = size + 1; |
| 217 | _items[size] = item; | ||
| 218 | return size; | ||
| 219 | } | ||
| 220 | |||
| 221 | /* | ||
| 222 | unsigned Add2(const T &item) | ||
| 223 | { | ||
| 224 | ReserveOnePosition(); | ||
| 225 | const unsigned size = _size; | ||
| 226 | _size = size + 1; | ||
| 227 | _items[size] = item; | ||
| 228 | return size; | ||
| 212 | } | 229 | } |
| 230 | */ | ||
| 213 | 231 | ||
| 214 | void AddInReserved(const T item) | 232 | unsigned AddInReserved(const T item) |
| 215 | { | 233 | { |
| 216 | _items[_size++] = item; | 234 | const unsigned size = _size; |
| 235 | _size = size + 1; | ||
| 236 | _items[size] = item; | ||
| 237 | return size; | ||
| 217 | } | 238 | } |
| 218 | 239 | ||
| 219 | void Insert(unsigned index, const T item) | 240 | void Insert(unsigned index, const T item) |
| @@ -224,6 +245,13 @@ public: | |||
| 224 | _size++; | 245 | _size++; |
| 225 | } | 246 | } |
| 226 | 247 | ||
| 248 | void InsertInReserved(unsigned index, const T item) | ||
| 249 | { | ||
| 250 | MoveItems(index + 1, index); | ||
| 251 | _items[index] = item; | ||
| 252 | _size++; | ||
| 253 | } | ||
| 254 | |||
| 227 | void MoveToFront(unsigned index) | 255 | void MoveToFront(unsigned index) |
| 228 | { | 256 | { |
| 229 | if (index != 0) | 257 | if (index != 0) |
| @@ -254,7 +282,8 @@ public: | |||
| 254 | { | 282 | { |
| 255 | while (left != right) | 283 | while (left != right) |
| 256 | { | 284 | { |
| 257 | unsigned mid = (left + right) / 2; | 285 | // const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2); |
| 286 | const unsigned mid = (left + right) / 2; | ||
| 258 | const T midVal = (*this)[mid]; | 287 | const T midVal = (*this)[mid]; |
| 259 | if (item == midVal) | 288 | if (item == midVal) |
| 260 | return (int)mid; | 289 | return (int)mid; |
| @@ -270,9 +299,10 @@ public: | |||
| 270 | { | 299 | { |
| 271 | while (left != right) | 300 | while (left != right) |
| 272 | { | 301 | { |
| 273 | unsigned mid = (left + right) / 2; | 302 | // const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2); |
| 303 | const unsigned mid = (left + right) / 2; | ||
| 274 | const T& midVal = (*this)[mid]; | 304 | const T& midVal = (*this)[mid]; |
| 275 | int comp = item.Compare(midVal); | 305 | const int comp = item.Compare(midVal); |
| 276 | if (comp == 0) | 306 | if (comp == 0) |
| 277 | return (int)mid; | 307 | return (int)mid; |
| 278 | if (comp < 0) | 308 | if (comp < 0) |
| @@ -298,7 +328,8 @@ public: | |||
| 298 | unsigned left = 0, right = _size; | 328 | unsigned left = 0, right = _size; |
| 299 | while (left != right) | 329 | while (left != right) |
| 300 | { | 330 | { |
| 301 | unsigned mid = (left + right) / 2; | 331 | // const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2); |
| 332 | const unsigned mid = (left + right) / 2; | ||
| 302 | const T midVal = (*this)[mid]; | 333 | const T midVal = (*this)[mid]; |
| 303 | if (item == midVal) | 334 | if (item == midVal) |
| 304 | return mid; | 335 | return mid; |
| @@ -316,9 +347,10 @@ public: | |||
| 316 | unsigned left = 0, right = _size; | 347 | unsigned left = 0, right = _size; |
| 317 | while (left != right) | 348 | while (left != right) |
| 318 | { | 349 | { |
| 319 | unsigned mid = (left + right) / 2; | 350 | // const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2); |
| 351 | const unsigned mid = (left + right) / 2; | ||
| 320 | const T& midVal = (*this)[mid]; | 352 | const T& midVal = (*this)[mid]; |
| 321 | int comp = item.Compare(midVal); | 353 | const int comp = item.Compare(midVal); |
| 322 | if (comp == 0) | 354 | if (comp == 0) |
| 323 | return mid; | 355 | return mid; |
| 324 | if (comp < 0) | 356 | if (comp < 0) |
| @@ -431,29 +463,35 @@ public: | |||
| 431 | CObjectVector() {} | 463 | CObjectVector() {} |
| 432 | CObjectVector(const CObjectVector &v) | 464 | CObjectVector(const CObjectVector &v) |
| 433 | { | 465 | { |
| 434 | unsigned size = v.Size(); | 466 | const unsigned size = v.Size(); |
| 435 | _v.ConstructReserve(size); | 467 | _v.ConstructReserve(size); |
| 436 | for (unsigned i = 0; i < size; i++) | 468 | for (unsigned i = 0; i < size; i++) |
| 437 | _v.AddInReserved(new T(v[i])); | 469 | AddInReserved(v[i]); |
| 438 | } | 470 | } |
| 439 | CObjectVector& operator=(const CObjectVector &v) | 471 | CObjectVector& operator=(const CObjectVector &v) |
| 440 | { | 472 | { |
| 441 | if (&v == this) | 473 | if (&v == this) |
| 442 | return *this; | 474 | return *this; |
| 443 | Clear(); | 475 | Clear(); |
| 444 | unsigned size = v.Size(); | 476 | const unsigned size = v.Size(); |
| 445 | _v.Reserve(size); | 477 | _v.Reserve(size); |
| 446 | for (unsigned i = 0; i < size; i++) | 478 | for (unsigned i = 0; i < size; i++) |
| 447 | _v.AddInReserved(new T(v[i])); | 479 | AddInReserved(v[i]); |
| 448 | return *this; | 480 | return *this; |
| 449 | } | 481 | } |
| 450 | 482 | ||
| 451 | CObjectVector& operator+=(const CObjectVector &v) | 483 | CObjectVector& operator+=(const CObjectVector &v) |
| 452 | { | 484 | { |
| 453 | unsigned size = v.Size(); | 485 | const unsigned addSize = v.Size(); |
| 454 | _v.Reserve(Size() + size); | 486 | if (addSize != 0) |
| 455 | for (unsigned i = 0; i < size; i++) | 487 | { |
| 456 | _v.AddInReserved(new T(v[i])); | 488 | const unsigned size = Size(); |
| 489 | if (size >= k_VectorSizeMax || addSize > k_VectorSizeMax - size) | ||
| 490 | throw 2021; | ||
| 491 | _v.Reserve(size + addSize); | ||
| 492 | for (unsigned i = 0; i < addSize; i++) | ||
| 493 | AddInReserved(v[i]); | ||
| 494 | } | ||
| 457 | return *this; | 495 | return *this; |
| 458 | } | 496 | } |
| 459 | 497 | ||
| @@ -466,14 +504,37 @@ public: | |||
| 466 | 504 | ||
| 467 | void MoveToFront(unsigned index) { _v.MoveToFront(index); } | 505 | void MoveToFront(unsigned index) { _v.MoveToFront(index); } |
| 468 | 506 | ||
| 469 | unsigned Add(const T& item) { return _v.Add(new T(item)); } | 507 | unsigned Add(const T& item) |
| 508 | { | ||
| 509 | _v.ReserveOnePosition(); | ||
| 510 | return AddInReserved(item); | ||
| 511 | } | ||
| 512 | |||
| 513 | unsigned AddInReserved(const T& item) | ||
| 514 | { | ||
| 515 | return _v.AddInReserved(new T(item)); | ||
| 516 | } | ||
| 517 | |||
| 518 | void ReserveOnePosition() | ||
| 519 | { | ||
| 520 | _v.ReserveOnePosition(); | ||
| 521 | } | ||
| 522 | |||
| 523 | unsigned AddInReserved_Ptr_of_new(T *ptr) | ||
| 524 | { | ||
| 525 | return _v.AddInReserved(ptr); | ||
| 526 | } | ||
| 527 | |||
| 528 | #define VECTOR_ADD_NEW_OBJECT(v, a) \ | ||
| 529 | (v).ReserveOnePosition(); \ | ||
| 530 | (v).AddInReserved_Ptr_of_new(new a); | ||
| 470 | 531 | ||
| 471 | void AddInReserved(const T& item) { _v.AddInReserved(new T(item)); } | ||
| 472 | 532 | ||
| 473 | T& AddNew() | 533 | T& AddNew() |
| 474 | { | 534 | { |
| 535 | _v.ReserveOnePosition(); | ||
| 475 | T *p = new T; | 536 | T *p = new T; |
| 476 | _v.Add(p); | 537 | _v.AddInReserved(p); |
| 477 | return *p; | 538 | return *p; |
| 478 | } | 539 | } |
| 479 | 540 | ||
| @@ -484,12 +545,17 @@ public: | |||
| 484 | return *p; | 545 | return *p; |
| 485 | } | 546 | } |
| 486 | 547 | ||
| 487 | void Insert(unsigned index, const T& item) { _v.Insert(index, new T(item)); } | 548 | void Insert(unsigned index, const T& item) |
| 549 | { | ||
| 550 | _v.ReserveOnePosition(); | ||
| 551 | _v.InsertInReserved(index, new T(item)); | ||
| 552 | } | ||
| 488 | 553 | ||
| 489 | T& InsertNew(unsigned index) | 554 | T& InsertNew(unsigned index) |
| 490 | { | 555 | { |
| 556 | _v.ReserveOnePosition(); | ||
| 491 | T *p = new T; | 557 | T *p = new T; |
| 492 | _v.Insert(index, p); | 558 | _v.InsertInReserved(index, p); |
| 493 | return *p; | 559 | return *p; |
| 494 | } | 560 | } |
| 495 | 561 | ||
| @@ -514,7 +580,7 @@ public: | |||
| 514 | 580 | ||
| 515 | void DeleteFrom(unsigned index) | 581 | void DeleteFrom(unsigned index) |
| 516 | { | 582 | { |
| 517 | unsigned size = _v.Size(); | 583 | const unsigned size = _v.Size(); |
| 518 | for (unsigned i = index; i < size; i++) | 584 | for (unsigned i = index; i < size; i++) |
| 519 | delete (T *)_v[i]; | 585 | delete (T *)_v[i]; |
| 520 | _v.DeleteFrom(index); | 586 | _v.DeleteFrom(index); |
| @@ -564,9 +630,10 @@ public: | |||
| 564 | unsigned left = 0, right = Size(); | 630 | unsigned left = 0, right = Size(); |
| 565 | while (left != right) | 631 | while (left != right) |
| 566 | { | 632 | { |
| 567 | unsigned mid = (left + right) / 2; | 633 | // const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2); |
| 634 | const unsigned mid = (left + right) / 2; | ||
| 568 | const T& midVal = (*this)[mid]; | 635 | const T& midVal = (*this)[mid]; |
| 569 | int comp = item.Compare(midVal); | 636 | const int comp = item.Compare(midVal); |
| 570 | if (comp == 0) | 637 | if (comp == 0) |
| 571 | return (int)mid; | 638 | return (int)mid; |
| 572 | if (comp < 0) | 639 | if (comp < 0) |
| @@ -582,9 +649,10 @@ public: | |||
| 582 | unsigned left = 0, right = Size(); | 649 | unsigned left = 0, right = Size(); |
| 583 | while (left != right) | 650 | while (left != right) |
| 584 | { | 651 | { |
| 585 | unsigned mid = (left + right) / 2; | 652 | // const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2); |
| 653 | const unsigned mid = (left + right) / 2; | ||
| 586 | const T& midVal = (*this)[mid]; | 654 | const T& midVal = (*this)[mid]; |
| 587 | int comp = item.Compare(midVal); | 655 | const int comp = item.Compare(midVal); |
| 588 | if (comp == 0) | 656 | if (comp == 0) |
| 589 | return mid; | 657 | return mid; |
| 590 | if (comp < 0) | 658 | if (comp < 0) |
| @@ -602,9 +670,10 @@ public: | |||
| 602 | unsigned left = 0, right = Size(); | 670 | unsigned left = 0, right = Size(); |
| 603 | while (left != right) | 671 | while (left != right) |
| 604 | { | 672 | { |
| 605 | unsigned mid = (left + right) / 2; | 673 | // const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2); |
| 674 | const unsigned mid = (left + right) / 2; | ||
| 606 | const T& midVal = (*this)[mid]; | 675 | const T& midVal = (*this)[mid]; |
| 607 | int comp = item.Compare(midVal); | 676 | const int comp = item.Compare(midVal); |
| 608 | if (comp == 0) | 677 | if (comp == 0) |
| 609 | { | 678 | { |
| 610 | right = mid + 1; | 679 | right = mid + 1; |
diff --git a/CPP/Common/MyWindows.h b/CPP/Common/MyWindows.h index 0664a5e..15db524 100644 --- a/CPP/Common/MyWindows.h +++ b/CPP/Common/MyWindows.h | |||
| @@ -76,7 +76,6 @@ typedef struct _FILETIME | |||
| 76 | DWORD dwHighDateTime; | 76 | DWORD dwHighDateTime; |
| 77 | } FILETIME; | 77 | } FILETIME; |
| 78 | 78 | ||
| 79 | #define HRESULT LONG | ||
| 80 | #define SUCCEEDED(hr) ((HRESULT)(hr) >= 0) | 79 | #define SUCCEEDED(hr) ((HRESULT)(hr) >= 0) |
| 81 | #define FAILED(hr) ((HRESULT)(hr) < 0) | 80 | #define FAILED(hr) ((HRESULT)(hr) < 0) |
| 82 | typedef ULONG PROPID; | 81 | typedef ULONG PROPID; |
| @@ -150,6 +149,7 @@ enum VARENUM | |||
| 150 | VT_VARIANT = 12, | 149 | VT_VARIANT = 12, |
| 151 | VT_UNKNOWN = 13, | 150 | VT_UNKNOWN = 13, |
| 152 | VT_DECIMAL = 14, | 151 | VT_DECIMAL = 14, |
| 152 | |||
| 153 | VT_I1 = 16, | 153 | VT_I1 = 16, |
| 154 | VT_UI1 = 17, | 154 | VT_UI1 = 17, |
| 155 | VT_UI2 = 18, | 155 | VT_UI2 = 18, |
diff --git a/CPP/Common/NewHandler.cpp b/CPP/Common/NewHandler.cpp index 7e5b1d4..65ef41d 100644 --- a/CPP/Common/NewHandler.cpp +++ b/CPP/Common/NewHandler.cpp | |||
| @@ -97,19 +97,33 @@ const int kDebugSize = 1000000; | |||
| 97 | static void *a[kDebugSize]; | 97 | static void *a[kDebugSize]; |
| 98 | static int index = 0; | 98 | static int index = 0; |
| 99 | 99 | ||
| 100 | static bool wasInit = false; | ||
| 101 | static CRITICAL_SECTION cs; | ||
| 102 | |||
| 100 | static int numAllocs = 0; | 103 | static int numAllocs = 0; |
| 101 | void * __cdecl operator new(size_t size) | 104 | void * __cdecl operator new(size_t size) |
| 102 | { | 105 | { |
| 106 | if (!wasInit) | ||
| 107 | { | ||
| 108 | InitializeCriticalSection(&cs); | ||
| 109 | wasInit = true; | ||
| 110 | } | ||
| 111 | EnterCriticalSection(&cs); | ||
| 112 | |||
| 103 | numAllocs++; | 113 | numAllocs++; |
| 114 | int loc = numAllocs; | ||
| 104 | void *p = HeapAlloc(GetProcessHeap(), 0, size); | 115 | void *p = HeapAlloc(GetProcessHeap(), 0, size); |
| 116 | /* | ||
| 105 | if (index < kDebugSize) | 117 | if (index < kDebugSize) |
| 106 | { | 118 | { |
| 107 | a[index] = p; | 119 | a[index] = p; |
| 108 | index++; | 120 | index++; |
| 109 | } | 121 | } |
| 122 | */ | ||
| 123 | printf("Alloc %6d, size = %8u\n", loc, (unsigned)size); | ||
| 124 | LeaveCriticalSection(&cs); | ||
| 110 | if (p == 0) | 125 | if (p == 0) |
| 111 | throw CNewException(); | 126 | throw CNewException(); |
| 112 | printf("Alloc %6d, size = %8u\n", numAllocs, (unsigned)size); | ||
| 113 | return p; | 127 | return p; |
| 114 | } | 128 | } |
| 115 | 129 | ||
| @@ -123,6 +137,7 @@ public: | |||
| 123 | } | 137 | } |
| 124 | ~CC() | 138 | ~CC() |
| 125 | { | 139 | { |
| 140 | printf("\nDestructor: %d\n", numAllocs); | ||
| 126 | for (int i = 0; i < kDebugSize; i++) | 141 | for (int i = 0; i < kDebugSize; i++) |
| 127 | if (a[i] != 0) | 142 | if (a[i] != 0) |
| 128 | return; | 143 | return; |
| @@ -134,6 +149,7 @@ void __cdecl operator delete(void *p) | |||
| 134 | { | 149 | { |
| 135 | if (p == 0) | 150 | if (p == 0) |
| 136 | return; | 151 | return; |
| 152 | EnterCriticalSection(&cs); | ||
| 137 | /* | 153 | /* |
| 138 | for (int i = 0; i < index; i++) | 154 | for (int i = 0; i < index; i++) |
| 139 | if (a[i] == p) | 155 | if (a[i] == p) |
| @@ -142,6 +158,7 @@ void __cdecl operator delete(void *p) | |||
| 142 | HeapFree(GetProcessHeap(), 0, p); | 158 | HeapFree(GetProcessHeap(), 0, p); |
| 143 | numAllocs--; | 159 | numAllocs--; |
| 144 | printf("Free %d\n", numAllocs); | 160 | printf("Free %d\n", numAllocs); |
| 161 | LeaveCriticalSection(&cs); | ||
| 145 | } | 162 | } |
| 146 | 163 | ||
| 147 | #endif | 164 | #endif |
diff --git a/CPP/Common/StringToInt.cpp b/CPP/Common/StringToInt.cpp index 839867a..bc4926e 100644 --- a/CPP/Common/StringToInt.cpp +++ b/CPP/Common/StringToInt.cpp | |||
| @@ -26,6 +26,33 @@ CONVERT_STRING_TO_UINT_FUNC(UInt32, wchar_t, wchar_t) | |||
| 26 | CONVERT_STRING_TO_UINT_FUNC(UInt64, char, Byte) | 26 | CONVERT_STRING_TO_UINT_FUNC(UInt64, char, Byte) |
| 27 | CONVERT_STRING_TO_UINT_FUNC(UInt64, wchar_t, wchar_t) | 27 | CONVERT_STRING_TO_UINT_FUNC(UInt64, wchar_t, wchar_t) |
| 28 | 28 | ||
| 29 | /* | ||
| 30 | Int32 ConvertStringToInt32(const char *s, const char **end) throw() | ||
| 31 | { | ||
| 32 | if (end) | ||
| 33 | *end = s; | ||
| 34 | const char *s2 = s; | ||
| 35 | if (*s == '-') | ||
| 36 | s2++; | ||
| 37 | if (*s2 == 0) | ||
| 38 | return 0; | ||
| 39 | const char *end2; | ||
| 40 | UInt32 res = ConvertStringToUInt32(s2, &end2); | ||
| 41 | if (*s == '-') | ||
| 42 | { | ||
| 43 | if (res > ((UInt32)1 << (32 - 1))) | ||
| 44 | return 0; | ||
| 45 | } | ||
| 46 | else if ((res & ((UInt32)1 << (32 - 1))) != 0) | ||
| 47 | return 0; | ||
| 48 | if (end) | ||
| 49 | *end = end2; | ||
| 50 | if (*s == '-') | ||
| 51 | return -(Int32)res; | ||
| 52 | return (Int32)res; | ||
| 53 | } | ||
| 54 | */ | ||
| 55 | |||
| 29 | Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw() | 56 | Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw() |
| 30 | { | 57 | { |
| 31 | if (end) | 58 | if (end) |
diff --git a/CPP/Common/StringToInt.h b/CPP/Common/StringToInt.h index 5c5d7d7..4057e49 100644 --- a/CPP/Common/StringToInt.h +++ b/CPP/Common/StringToInt.h | |||
| @@ -10,6 +10,7 @@ UInt64 ConvertStringToUInt64(const char *s, const char **end) throw(); | |||
| 10 | UInt32 ConvertStringToUInt32(const wchar_t *s, const wchar_t **end) throw(); | 10 | UInt32 ConvertStringToUInt32(const wchar_t *s, const wchar_t **end) throw(); |
| 11 | UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end) throw(); | 11 | UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end) throw(); |
| 12 | 12 | ||
| 13 | // Int32 ConvertStringToInt32(const char *s, const char **end) throw(); | ||
| 13 | Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw(); | 14 | Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw(); |
| 14 | 15 | ||
| 15 | UInt32 ConvertOctStringToUInt32(const char *s, const char **end) throw(); | 16 | UInt32 ConvertOctStringToUInt32(const char *s, const char **end) throw(); |
