MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / IncrementOffset

Function IncrementOffset

tensorflow/core/lib/wav/wav_io.cc:88–109  ·  view source on GitHub ↗

Handles moving the data index forward, validating the arguments, and avoiding overflow or underflow.

Source from the content-addressed store, hash-verified

86// Handles moving the data index forward, validating the arguments, and avoiding
87// overflow or underflow.
88Status IncrementOffset(int old_offset, size_t increment, size_t max_size,
89 int* new_offset) {
90 if (old_offset < 0) {
91 return errors::InvalidArgument("Negative offsets are not allowed: ",
92 old_offset);
93 }
94 if (old_offset > max_size) {
95 return errors::InvalidArgument("Initial offset is outside data range: ",
96 old_offset);
97 }
98 *new_offset = old_offset + increment;
99 if (*new_offset > max_size) {
100 return errors::InvalidArgument("Data too short when trying to read string");
101 }
102 // See above for the check that the input offset is positive. If it's negative
103 // here then it means that there's been an overflow in the arithmetic.
104 if (*new_offset < 0) {
105 return errors::InvalidArgument("Offset too large, overflowed: ",
106 *new_offset);
107 }
108 return Status::OK();
109}
110
111Status ExpectText(const string& data, const string& expected_text,
112 int* offset) {

Callers 5

TESTFunction · 0.85
ExpectTextFunction · 0.85
ReadStringFunction · 0.85
ReadValueFunction · 0.85

Calls 1

InvalidArgumentFunction · 0.85

Tested by 1

TESTFunction · 0.68