summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sqlite.zig25
1 files changed, 17 insertions, 8 deletions
diff --git a/sqlite.zig b/sqlite.zig
index e4bcb45..537ae02 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -901,18 +901,27 @@ pub fn Iterator(comptime Type: type) type {
901 switch (arr.child) { 901 switch (arr.child) {
902 u8 => { 902 u8 => {
903 const size = @intCast(usize, c.sqlite3_column_bytes(self.stmt, i)); 903 const size = @intCast(usize, c.sqlite3_column_bytes(self.stmt, i));
904 if (arr.sentinel == null) { 904
905 if (size != arr.len) return error.ArraySizeMismatch; 905 if (arr.sentinel) |s| {
906 } else if (size >= @as(usize, arr.len)) { 906 // An array with a sentinel need to be as big as the data, + 1 byte for the sentinel.
907 return error.ArrayTooSmall; 907 mem.set(u8, &ret, s);
908 if (size >= @as(usize, arr.len)) {
909 return error.ArrayTooSmall;
910 }
911 } else if (size != arr.len) {
912 // An array without a sentinel must have the exact same size as the data because we can't
913 // communicate the real size to the caller.
914 return error.ArraySizeMismatch;
908 } 915 }
909 916
910 const data = c.sqlite3_column_blob(self.stmt, i); 917 const data = c.sqlite3_column_blob(self.stmt, i);
911 const ptr = @ptrCast([*c]const u8, data)[0..size]; 918 if (data != null) {
919 const ptr = @ptrCast([*c]const u8, data)[0..size];
912 920
913 mem.copy(u8, ret[0..], ptr); 921 mem.copy(u8, ret[0..], ptr);
914 if (arr.sentinel) |s| { 922 if (arr.sentinel) |s| {
915 ret[size] = s; 923 ret[size] = s;
924 }
916 } 925 }
917 }, 926 },
918 else => @compileError("cannot read into array of " ++ @typeName(arr.child)), 927 else => @compileError("cannot read into array of " ++ @typeName(arr.child)),