summaryrefslogtreecommitdiff
path: root/src/buffer.c
Commit message (Collapse)AuthorAgeFilesLines
* buffer: explicitly castEdward Thomson2019-01-251-1/+1
| | | | | Quiet down a warning from MSVC about how we're potentially losing data. This is safe since we've explicitly tested it.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-45/+45
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-3/+3
|
* buffer: deprecate `git_buf_free` in favor of `git_buf_dispose`Patrick Steinhardt2018-06-101-1/+6
|
* Introduce `git_buf_decode_percent`Edward Thomson2018-03-191-1/+31
| | | | | Introduce a function to take a percent-encoded string (URI encoded, described by RFC 1738) and decode it into a `git_buf`.
* buffer: return errors for `git_buf_init` and `git_buf_attach`Patrick Steinhardt2017-06-081-6/+8
| | | | | | | | | | Both the `git_buf_init` and `git_buf_attach` functions may call `git_buf_grow` in case they were given an allocation length as parameter. As such, it is possible for these functions to fail when we run out of memory. While it won't probably be used anytime soon, it does indeed make sense to also record this fact by returning an error code from both functions. As they belong to the internal API only, this change does not break our interface.
* buffer: consistently use `ENSURE_SIZE` to grow buffers on-demandPatrick Steinhardt2017-06-081-5/+2
| | | | | | | | | | | The `ENSURE_SIZE` macro can be used to grow a buffer if its currently allocated size does not suffice a required target size. While most of the code already uses this macro, the `git_buf_join` and `git_buf_join3` functions do not yet use it. Due to the macro first checking whether we have to grow the buffer at all, this has the benefit of saving a function call when it is not needed. While this is nice to have, it will probably not matter at all performance-wise -- instead, this only serves for consistency across the code.
* buffer: fix `ENSURE_SIZE` macro referencing wrong variablePatrick Steinhardt2017-06-081-1/+1
| | | | | | | | | | | | | | While the `ENSURE_SIZE` macro gets a reference to both the buffer that is to be resized and a new size, we were not consistently referencing the passed buffer, but instead a variable `buf`, which is not passed in. Funnily enough, we never noticed because our buffers seem to always be named `buf` whenever the macro was being used. Fix the macro by always using the passed-in buffer. While at it, add braces around all mentions of passed-in variables as should be done with macros to avoid subtle errors. Found-by: Edward Thompson
* giterr_set: consistent error messagesEdward Thomson2016-12-291-4/+4
| | | | | | | | Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
* git_buf_quote/unquote: handle > \177Edward Thomson2016-05-261-2/+2
| | | | | | Parse values up to and including `\377` (`0xff`) when unquoting. Print octal values as an unsigned char when quoting, lest `printf` think we're talking about negatives.
* git_buf_quote: quote ugly charactersEdward Thomson2016-05-261-0/+66
|
* git_buf: decode base85 inputsEdward Thomson2016-05-261-20/+111
|
* Patch parsing from patch filesEdward Thomson2016-05-261-0/+75
|
* buffer: make use of EINVALID for growing a borrowed bufferCarlos Martín Nieto2015-06-241-2/+4
| | | | | This explains more closely what happens. While here, set an error message.
* buffer: don't allow growing borrowed buffersCarlos Martín Nieto2015-06-241-6/+6
| | | | | | | | | | When we don't own a buffer (asize=0) we currently allow the usage of grow to copy the memory into a buffer we do own. This muddles the meaning of grow, and lets us be a bit cavalier with ownership semantics. Don't allow this any more. Usage of grow should be restricted to buffers which we know own their own memory. If unsure, we must not attempt to modify it.
* buffer: introduce git_buf_attach_notownedEdward Thomson2015-02-191-0/+14
| | | | | | Provide a convenience function that creates a buffer that can be provided to callers but will not be freed via `git_buf_free`, so the buffer creator maintains the allocation lifecycle of the buffer's contents.
* Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-67/+76
| | | | | | | | | Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
* overflow checking: don't make callers set oomEdward Thomson2015-02-121-1/+0
| | | | | | Have the ALLOC_OVERFLOW testing macros also simply set_oom in the case where a computation would overflow, so that callers don't need to.
* git_buf_grow_by: increase buf asize incrementallyEdward Thomson2015-02-121-3/+14
| | | | | Introduce `git_buf_grow_by` to incrementally increase the size of a `git_buf`, performing an overflow calculation on the growth.
* allocations: test for overflow of requested sizeEdward Thomson2015-02-121-5/+57
| | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* Fix crash in free() when git_buf_grow() fails.Jeff Hostetler2015-01-091-1/+2
|
* buffer: Do not `put` anything if len is 0Vicent Marti2014-11-211-4/+7
|
* Introduce git_buf_decode_base64Edward Thomson2014-08-151-10/+56
| | | | Decode base64-encoded text into a git_buf
* Just put it all in buffer.joshaber2014-07-161-0/+11
|
* Be more careful with user-supplied buffersrb/fix-2333Russell Belfer2014-05-081-15/+22
| | | | | | | | | | | This adds in missing calls to `git_buf_sanitize` and fixes a number of places where `git_buf` APIs could inadvertently write NUL terminator bytes into invalid buffers. This also changes the behavior of `git_buf_sanitize` to NUL terminate a buffer if it can and of `git_buf_shorten` to do nothing if it can. Adds tests of filtering code with zeroed (i.e. unsanitized) buffer which was previously triggering a segfault.
* patch: emit binary patches (optionally)Edward Thomson2014-04-221-0/+36
|
* Introduce git_buf_putcnJacques Germishuys2014-04-101-0/+9
| | | | Allows for inserting the same character n amount of times
* Add efficient git_buf join3 APIRussell Belfer2014-04-011-0/+53
| | | | | | | There are a few places where we need to join three strings to assemble a path. This adds a simple join3 function to avoid the comparatively expensive join_n (which calls strlen on each string twice).
* Remove now-duplicated stdarg.h includeEdward Thomson2014-02-241-1/+0
|
* fix corner cases and an undefined behaviorPatrick Reynolds2014-01-201-3/+6
|
* Handle git_buf's from users more liberallyEdward Thomson2014-01-081-0/+8
|
* Clean up unnecessary git_buf_printf callsRussell Belfer2013-09-231-0/+2
| | | | | | This replaces some git_buf_printf calls with simple calls to git_buf_put instead. Also, it fixes a missing va_end inside the git_buf_vprintf implementation.
* Merge pull request #1840 from linquize/warningVicent Martí2013-09-211-1/+1
|\ | | | | Fix warning
| * Fix warningLinquize2013-09-191-1/+1
| |
* | Merge git_buf and git_bufferRussell Belfer2013-09-171-74/+19
| | | | | | | | | | | | | | | | | | | | | | This makes the git_buf struct that was used internally into an externally available structure and eliminates the git_buffer. As part of that, some of the special cases that arose with the externally used git_buffer were blended into the git_buf, such as being careful about git_buf objects that may have a NULL ptr and allowing for bufs with a valid ptr and size but zero asize as a way of referring to externally owned data.
* | Add functions to manipulate filter listsRussell Belfer2013-09-171-1/+2
| | | | | | | | | | | | | | | | Extend the git2/sys/filter API with functions to look up a filter and add it manually to a filter list. This requires some trickery because the regular attribute lookups and checks are bypassed when this happens, but in the right hands, it will allow a user to have granular control over applying filters.
* | Extend public filter api with filter listsRussell Belfer2013-09-171-3/+20
| | | | | | | | | | | | | | | | | | | | | | This moves the git_filter_list into the public API so that users can create, apply, and dispose of filter lists. This allows more granular application of filters to user data outside of libgit2 internals. This also converts all the internal usage of filters to the public APIs along with a few small tweaks to make it easier to use the public git_buffer stuff alongside the internal git_buf.
* | Start of filter API + git_blob_filtered_contentRussell Belfer2013-09-171-0/+54
|/ | | | | | | | | | This begins the process of exposing git_filter objects to the public API. This includes: * new public type and API for `git_buffer` through which an allocated buffer can be passed to the user * new API `git_blob_filtered_content` * make the git_filter type and GIT_FILTER_TO_... constants public
* Add helpful buffer shorten functionRussell Belfer2013-07-011-0/+9
|
* update copyrightsEdward Thomson2013-01-081-1/+1
|
* Consolidate text buffer functionsRussell Belfer2012-11-281-108/+6
| | | | | | | | | | | | | There are many scattered functions that look into the contents of buffers to do various text manipulations (such as escaping or unescaping data, calculating text stats, guessing if content is binary, etc). This groups all those functions together into a new file and converts the code to use that. This has two enhancements to existing functionality. The old text stats function is significantly rewritten and the BOM detection code was extended (although largely we can't deal with anything other than a UTF8 BOM).
* buf: introduce git_buf_splice()nulltoken2012-10-251-0/+28
|
* Fix buffer overrun in git_buf_put_base64Philip Kelley2012-10-141-1/+1
|
* Add git_buf_put_base64 to buffer APIRussell Belfer2012-10-101-0/+40
|
* Fix valgrind issues and leaksRussell Belfer2012-08-241-14/+23
| | | | | | This fixes up a number of problems flagged by valgrind and also cleans up the internal `git_submodule` allocation handling overall with a simpler model.
* Add git_buf_unescape and git__unescape to unescape all characters in a ↵yorah2012-07-241-0/+4
| | | | string (in-place)
* Fix missing NUL termination of bufferRussell Belfer2012-07-101-0/+2
|
* Add a couple of useful git_buf utilitiesRussell Belfer2012-07-101-0/+34
| | | | | | | * `git_buf_rfind` (with tests and tests for `git_buf_rfind_next`) * `git_buf_puts_escaped` and `git_buf_puts_escaped_regex` (with tests) to copy strings into a buffer while injecting an escape sequence (e.g. '\') in front of particular characters.
* misc: Fix warnings from PVS Studio trialVicent Martí2012-06-071-1/+2
|
* No point in keeping commented out fnRussell Belfer2012-05-171-9/+0
|