GNOME Bugzilla – Bug 756906
GBytes: add range-checked pointer getter
Last modified: 2018-05-24 18:18:52 UTC
Add a helper to GBytes to perform the common task of: - multiplying an element size times an array length, with bounds checks - adding it to an offset, with bounds checks - ensuring the resulting end offset is in range of the GBytes - returning a pointer to the start of the range This is built on the new efficient checked integer arithmetic macros introduced in bug 756903. Also add a testcase.
Created attachment 313811 [details] [review] GBytes: add range-checked pointer getter
(In reply to Ryan Lortie (desrt) from comment #0) > Add a helper to GBytes to perform the common task of: ^[citation required]
(In reply to Dan Winship from comment #2) > (In reply to Ryan Lortie (desrt) from comment #0) > > Add a helper to GBytes to perform the common task of: > ^[citation required] See bug #756026 for one example; bug #756100 for another. Basically anything where structured data is being loaded from an mmap()ed file.
Review of attachment 313811 [details] [review]: ::: glib/gbytes.c @@ +500,3 @@ + +/** + * g_bytes_get_pointer: The name implies to me that this does the same as g_bytes_get_data() — i.e. it returns the base point of the GBytes. How about g_bytes_get_region()? @@ +515,3 @@ + * + * This function does careful bounds checking (including checking for + * arithmatic overflows) and returns a non-%NULL pointer if the s/arithmatic/arithmetic/ @@ +520,3 @@ + * is returned. + * + * Note: it is possible to have a valid zero-size range. In this case, s/range/region/, since that's what you've used elsewhere in the docs. Maybe also clarify that this is the case iff @n_elements is zero. Combine it with the paragraph which states that (paragraph 3)? @@ +545,3 @@ + + if (!GSIZE_CHECKED_MUL (&total_size, element_size, n_elements)) + return FALSE; s/FALSE/NULL/, and below.
I will redo the patch once we come to a conclusion on bug 503096.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/1098.