From 7ada79b5caba51b63577239100a4cb5e2cd552cf Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sat, 28 Jan 2023 17:07:05 +0100 Subject: [PATCH] Don't use deprecated Readonly_file::read variants Issue #4745 --- repos/gems/include/gems/vfs_font.h | 22 +++++++++++----------- repos/gems/src/lib/vfs/import/plugin.cc | 3 ++- repos/os/src/test/vfs_capture/main.cc | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/repos/gems/include/gems/vfs_font.h b/repos/gems/include/gems/vfs_font.h index ccbac1acb7..5ee2089df3 100644 --- a/repos/gems/include/gems/vfs_font.h +++ b/repos/gems/include/gems/vfs_font.h @@ -79,23 +79,21 @@ class Genode::Vfs_font : public Text_painter::Font Area const _bounding_box; unsigned const _height; - struct Glyph_buffer + struct Glyph_buffer : Byte_range_ptr { Allocator &_alloc; - size_t const num_bytes; + Glyph_header &header { *(Glyph_header *)start }; - Glyph_header &header; + static size_t _bytes(Area size) { return sizeof(Glyph_buffer) + size.count()*4; } Glyph_buffer(Allocator &alloc, Area size) : - _alloc(alloc), num_bytes(sizeof(Glyph_header) + size.count()*4), - header(*(Glyph_header *)alloc.alloc(num_bytes)) + Byte_range_ptr((char *)alloc.alloc(_bytes(size)), _bytes(size)), + _alloc(alloc) { } - ~Glyph_buffer() { _alloc.free(&header, num_bytes); } - - char *ptr() { return (char *)&header; } + ~Glyph_buffer() { _alloc.free(start, num_bytes); } }; Glyph_buffer mutable _buffer; @@ -110,7 +108,7 @@ class Genode::Vfs_font : public Text_painter::Font try { Readonly_file const file(dir, path); char buf[MAX_LEN + 1] { }; - if (file.read(buf, sizeof(buf)) <= MAX_LEN) + if (file.read(Byte_range_ptr { buf, sizeof(buf) }) <= MAX_LEN) if (ascii_to(buf, result)) return result; } @@ -149,14 +147,16 @@ class Genode::Vfs_font : public Text_painter::Font void _apply_glyph(Codepoint c, Apply_fn const &fn) const override { - _glyphs_file.read(_file_pos(c), _buffer.ptr(), _buffer.num_bytes); + _glyphs_file.read(_file_pos(c), _buffer); fn.apply(_buffer.header.glyph()); } Advance_info advance_info(Codepoint c) const override { - _glyphs_file.read(_file_pos(c), _buffer.ptr(), sizeof(Glyph_header)); + Byte_range_ptr header_buffer { _buffer.start, sizeof(Glyph_header) }; + + _glyphs_file.read(_file_pos(c), header_buffer); Glyph const glyph = _buffer.header.glyph(); diff --git a/repos/gems/src/lib/vfs/import/plugin.cc b/repos/gems/src/lib/vfs/import/plugin.cc index 603d320471..311c18890f 100644 --- a/repos/gems/src/lib/vfs/import/plugin.cc +++ b/repos/gems/src/lib/vfs/import/plugin.cc @@ -146,7 +146,8 @@ class Vfs_import::File_system : public Vfs::File_system while (true) { - file_size bytes_from_source { src_file.read(at, buf, sizeof(buf)) }; + file_size const bytes_from_source = + src_file.read(at, Genode::Byte_range_ptr(buf, sizeof(buf))); if (!bytes_from_source) break; diff --git a/repos/os/src/test/vfs_capture/main.cc b/repos/os/src/test/vfs_capture/main.cc index fa6452f8e9..71f77be575 100644 --- a/repos/os/src/test/vfs_capture/main.cc +++ b/repos/os/src/test/vfs_capture/main.cc @@ -168,8 +168,8 @@ struct Test::Main { } Affected_rects capture() { - _capture_file.read(_capture_ds.local_addr(), - _capture_ds_size); + _capture_file.read(Byte_range_ptr(_capture_ds.local_addr(), + _capture_ds_size)); Affected_rects affected { }; affected.rects[0] = Rect(_at, _area); return affected;