Commit 2d449a11 by Nelson Elhage

config: Refactor `git_config_backend_from_string` to take a length

parent b37a5954
......@@ -30,8 +30,9 @@ extern int git_config_backend_from_file(git_config_backend **out, const char *pa
*
* @param out the new backend
* @param cfg the configuration that is to be parsed
* @param len the length of the string pointed to by `cfg`
*/
extern int git_config_backend_from_string(git_config_backend **out, const char *cfg);
extern int git_config_backend_from_string(git_config_backend **out, const char *cfg, size_t len);
GIT_INLINE(int) git_config_backend_open(git_config_backend *cfg, unsigned int level, const git_repository *repo)
{
......
......@@ -186,7 +186,7 @@ static void config_memory_free(git_config_backend *_backend)
git__free(backend);
}
int git_config_backend_from_string(git_config_backend **out, const char *cfg)
int git_config_backend_from_string(git_config_backend **out, const char *cfg, size_t len)
{
config_memory_backend *backend;
......@@ -198,7 +198,7 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg)
return -1;
}
if (git_buf_sets(&backend->cfg, cfg) < 0) {
if (git_buf_put(&backend->cfg, cfg, len) < 0) {
git_config_entries_free(backend->entries);
git__free(backend);
return -1;
......
......@@ -61,7 +61,7 @@ static void assert_config_contains_all(git_config_backend *backend,
static void setup_backend(const char *cfg)
{
cl_git_pass(git_config_backend_from_string(&backend, cfg));
cl_git_pass(git_config_backend_from_string(&backend, cfg, strlen(cfg)));
cl_git_pass(git_config_backend_open(backend, 0, NULL));
}
......@@ -85,9 +85,10 @@ void test_config_memory__simple(void)
void test_config_memory__malformed_fails_to_open(void)
{
cl_git_pass(git_config_backend_from_string(&backend,
const char *cfg =
"[general\n"
"foo=bar\n"));
"foo=bar\n";
cl_git_pass(git_config_backend_from_string(&backend, cfg, strlen(cfg)));
cl_git_fail(git_config_backend_open(backend, 0, NULL));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment