freetype: Avoid dereferencing null bitmap buffer.
For some characters (eg \r) the returned glyph will have .{.rows = 0, .width=0, .pitch = 0, .buffer = null}. In zig null[0..0] causes a panic rather than returning an empty slice.
This commit is contained in:
parent
86053d9969
commit
15c71f5135
2 changed files with 8 additions and 3 deletions
|
|
@ -45,8 +45,13 @@ pub const Bitmap = struct {
|
|||
return @intToEnum(PixelMode, self.handle.pixel_mode);
|
||||
}
|
||||
|
||||
pub fn buffer(self: Bitmap) []const u8 {
|
||||
pub fn buffer(self: Bitmap) ?[]const u8 {
|
||||
const buffer_size = std.math.absCast(self.pitch()) * self.rows();
|
||||
return self.handle.buffer[0..buffer_size];
|
||||
return if (self.handle.buffer == null)
|
||||
// freetype returns a null pointer for zero-length allocations
|
||||
// https://github.com/hexops/freetype/blob/bbd80a52b7b749140ec87d24b6c767c5063be356/freetype/src/base/ftutil.c#L135
|
||||
null
|
||||
else
|
||||
self.handle.buffer[0..buffer_size];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue