summaryrefslogtreecommitdiff
path: root/glib/gbytes.c
Commit message (Collapse)AuthorAgeFilesLines
* glib: Add SPDX license headers automaticallyPhilip Withnall2022-05-181-0/+2
| | | | | | | | | | | | | | Add SPDX license (but not copyright) headers to all files which follow a certain pattern in their existing non-machine-readable header comment. This commit was entirely generated using the command: ``` git ls-files glib/*.[ch] | xargs perl -0777 -pi -e 's/\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/\n \*\n \* SPDX-License-Identifier: LGPL-2.1-or-later\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/igs' ``` Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Helps: #1415
* GBytes: add range-checked pointer getterNitin Wartkar2021-06-151-0/+72
| | | | | | Updated and improved by Nitin Wartkar. Fixes: #1098
* gbytearray: Do not accept too large byte arraysKrzesimir Nowak2021-02-111-0/+4
| | | | | | | | | | | | GByteArray uses guint for storing the length of the byte array, but it also has a constructor (g_byte_array_new_take) that takes length as a gsize. gsize may be larger than guint (64 bits for gsize vs 32 bits for guint). It is possible to call the function with a value greater than G_MAXUINT, which will result in silent length truncation. This may happen as a result of unreffing GBytes into GByteArray, so rather be loud about it. (Test case tweaked by Philip Withnall.)
* glib: Use g_memdup2() instead of g_memdup() in obvious placesPhilip Withnall2021-02-041-2/+2
| | | | | | | | | | | | | | | | | Convert all the call sites which use `g_memdup()`’s length argument trivially (for example, by passing a `sizeof()` or an existing `gsize` variable), so that they use `g_memdup2()` instead. In almost all of these cases the use of `g_memdup()` would not have caused problems, but it will soon be deprecated, so best port away from it In particular, this fixes an overflow within `g_bytes_new()`, identified as GHSL-2021-045 by GHSL team member Kevin Backhouse. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: GHSL-2021-045 Helps: #2319
* gbytes: Avoid memcmp (NULL, ., 0) or memcmp (., NULL, 0)Simon McVittie2019-11-041-1/+1
| | | | | | | | | | | | | Similar to 3837b83f, glibc memcmp is declared with the first two arguments annotated as non-null via an attribute, which results in the undefined behaviour sanitizer considering it to be UB to pass a null pointer there (even if we are comparing 0 bytes, and hence not actually dereferencing the pointer). This shows up in /gvariant/serialiser/children when run with the undefined behaviour sanitizer. Signed-off-by: Simon McVittie <smcv@collabora.com>
* Fix up g_bytes_compare() documentationSebastian Dröge2018-08-061-3/+11
| | | | | It was declaring the opposite of what the function was actually doing, and what every other comparison function is doing.
* Port GBytes to gatomicrefcountEmmanuele Bassi2018-06-111-5/+6
| | | | | Use the newly added API for reference counting instead of rolling our own.
* tests: additional test for g_bytes_new_from_bytes()Christian Hergert2018-01-271-0/+1
| | | | | | | | | | | | | | | | This adds two new tests for g_bytes_new_from_bytes(). One test ensures that when creating a new GBytes that is a slice of the entire base bytes, we just return the base bytes with it's reference count incremented by one. The other test ensures that when performing sub-slices of GBytes, for which the parent GBytes also references a GBytes, that we skip the intermediate GBytes and reference the base GBytes. Additional testing of the internal state of the GBytes structure is performed to prove the correctness of the implementation. https://bugzilla.gnome.org/show_bug.cgi?id=792780
* bytes: avoid intermediate refs in g_bytes_new_from_bytes()Christian Hergert2018-01-271-1/+26
| | | | | | | | | | | When referencing a GBytes that is already a slice of another GBytes, we can avoid referencing the intermediate GBytes and instead reference the root bytes. Doing so helps avoid keeping N GBytes instances alive when the intermediates would have otherwise been finalized. https://bugzilla.gnome.org/show_bug.cgi?id=792780
* gbytes: Clarify nullability for g_bytes_unref() in docsUmang Jain2017-12-071-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=791318
* docs: add missing '*' chars at start of doc-commentsStefan Sauer2017-11-121-3/+3
|
* gbytes: Fix check in try_steal_and_unrefChristian Persch2017-10-061-1/+2
| | | | | | | Need to check if the user data is equal to the data, before taking the data out of the GBytes! Bug #670139.
* glib/: LGPLv2+ -> LGPLv2.1+Sébastien Wilmet2017-05-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All glib/*.{c,h} files have been processed, as well as gtester-report. 12 of those files are not licensed under LGPL: gbsearcharray.h gconstructor.h glibintl.h gmirroringtable.h gscripttable.h gtranslit-data.h gunibreak.h gunichartables.h gunicomp.h gunidecomp.h valgrind.h win_iconv.c Some of them are generated files, some are licensed under a BSD-style license and win_iconv.c is in the public domain. Sub-directories inside glib/: deprecated/: processed in a previous commit glib-mirroring-tab/: already LGPLv2.1+ gnulib/: not modified, the code is copied from gnulib libcharset/: a copy pcre/: a copy tests/: processed in a previous commit https://bugzilla.gnome.org/show_bug.cgi?id=776504
* glib: Add missing (nullable) and (optional) annotationsPhilip Withnall2015-11-071-2/+3
| | | | | | | | | | | | | | | | | | Add various (nullable) and (optional) annotations which were missing from a variety of functions. Also port a couple of existing (allow-none) annotations in the same files to use (nullable) and (optional) as appropriate instead. Secondly, add various (not nullable) annotations as needed by the new default in gobject-introspection of marking gpointers as (nullable). See https://bugzilla.gnome.org/show_bug.cgi?id=729660. This includes adding some stub documentation comments for the assertion macro error functions, which weren’t previously documented. The new comments are purely to allow for annotations, and hence are marked as (skip) to prevent the symbols appearing in the GIR file. https://bugzilla.gnome.org/show_bug.cgi?id=719966
* Skip g_bytes_new_with_free_func() in introspectionMikhail Zabaluev2015-10-011-1/+1
| | | | | | | The tricky ownership/mutability semantics on data make this function unusable in introspection. https://bugzilla.gnome.org/show_bug.cgi?id=755961
* gbytes: fix up annotationsMikhail Zabaluev2015-10-011-11/+12
| | | | | | | | Annotate array elements as bytes. Annotate a missed output parameter. Replace (allow-none) with the corresponding modern annotations. https://bugzilla.gnome.org/show_bug.cgi?id=755961
* Fix typos in gbytes_hash and g_time_zone_find_interval docsGergely POLONKAI2014-07-141-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=733084
* Updated FSF's addressDaniel Mustieles2014-01-311-3/+1
|
* gbytes: Clarify the nullability of GBytes->dataPhilip Withnall2013-11-271-12/+26
| | | | | | | Clarify that it is permitted for a GBytes to contain a NULL data pointer, as long as its size is 0. https://bugzilla.gnome.org/show_bug.cgi?id=715164
* GBytes: Add missing annotationsMartin Pitt2012-11-091-5/+9
| | | | | | | | | | | Annotate g_bytes_new*()'s data argument to be a guint8 array, as introspection clients cannot deal with raw gconstpointers. This makes GBytes' behaviour similar to GByteArray whose API already uses guint8. Add missing transfer annotation to g_bytes_get_data() to make it introspectable. This is covered by test cases in PyGObject.
* GBytes: deal with a corner-caseMatthias Clasen2012-10-161-1/+1
| | | | | | When calling g_bytes_unref_to_data on a GBytes with NULL data we could end up with double-free or use-after-free issues. https://bugzilla.gnome.org/show_bug.cgi?id=686091
* GBytes: add a size argument to g_bytes_get_dataStef Walter2011-12-151-2/+6
| | | | | | | * An out size argument so that this is more easily bindable by gobject-introspection. https://bugzilla.gnome.org/show_bug.cgi?id=665879
* GBytes: A new type for an immutable set of bytes.Stef Walter2011-11-241-0/+478
* Represents an immutable reference counted block of memory. * This is basically the internal glib GBuffer structure exposed, renamed, and with some additional capabilities. * The GBytes name comes from python3's immutable 'bytes' type * GBytes can be safely used as keys in hash tables, and have functions for doing so: g_bytes_hash, g_bytes_equal * GByteArray is a mutable form of GBytes, and vice versa. There are functions for converting from one to the other efficiently: g_bytes_unref_to_array() and g_byte_array_free_to_bytes() * Adds g_byte_array_new_take() to support above functions https://bugzilla.gnome.org/show_bug.cgi?id=663291