Skip to content

Commit

Permalink
Fixed integer overflow error (#7)
Browse files Browse the repository at this point in the history
* Fix integer overflow error

```
 {
        // wrong command
        var stream = t.Stream.init();
        stream.add("invalid data\r\n");
        var client = TestClient.init(stream, config);
        defer client.deinit();

        try t.expectError(error.SyntaxErrorOrCommandNotFound, client.hello());
    }

```
  • Loading branch information
arshidkv12 authored Aug 12, 2024
1 parent 85ead77 commit 318b79a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/reader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,16 @@ pub const Reply = struct {

// our caller made sure that data.len >= 3
fn parse(raw: []const u8) Reply {
const firstByte = if (raw[0] >= '0' and raw[0] <= '9') ((@as(u16, raw[0]) - '0') * 100) else 500;
const secondByte = if (raw[2] >= '0' and raw[2] <= '9') ((@as(u16, raw[1]) - '0') * 10) else 0;
const thirdByte = if (raw[2] >= '0' and raw[2] <= '9') (raw[2] - '0') else 0;
const code = firstByte + secondByte + thirdByte;

return .{
.raw = raw,
.more = raw.len > 3 and raw[3] == '-',
.data = if (raw.len > 4) raw[4..] else "",
.code = ((@as(u16, raw[0]) - '0') * 100) + ((@as(u16, raw[1]) - '0') * 10) + (raw[2] - '0'),
.code = code,
};
}
};
Expand Down

0 comments on commit 318b79a

Please sign in to comment.