diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/nu/SafeSize.h | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/replicant/nu/SafeSize.h')
-rw-r--r-- | Src/replicant/nu/SafeSize.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Src/replicant/nu/SafeSize.h b/Src/replicant/nu/SafeSize.h new file mode 100644 index 00000000..02c97a07 --- /dev/null +++ b/Src/replicant/nu/SafeSize.h @@ -0,0 +1,51 @@ +#pragma once + +class SafeSize +{ +public: + SafeSize() + { + value = 0; + overflow = false; + } + + void Add(size_t add) + { + if (!overflow) + { + value += add; + if (value < add) + overflow=true; + } + } + + void AddN(size_t size, size_t count) + { + if (!overflow) + { + size_t total = size * count; + if (total < size) + { + overflow = true; + } + else + { + Add(total); + } + } + } + + bool Overflowed() const + { + return overflow; + } + + operator size_t () + { + return value; + } + +private: + size_t value; + bool overflow; +};
\ No newline at end of file |