Skip to content

Commit 2d449a1

Browse files
committed
config: Refactor git_config_backend_from_string to take a length
1 parent b37a595 commit 2d449a1

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/config_backend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ extern int git_config_backend_from_file(git_config_backend **out, const char *pa
3030
*
3131
* @param out the new backend
3232
* @param cfg the configuration that is to be parsed
33+
* @param len the length of the string pointed to by `cfg`
3334
*/
34-
extern int git_config_backend_from_string(git_config_backend **out, const char *cfg);
35+
extern int git_config_backend_from_string(git_config_backend **out, const char *cfg, size_t len);
3536

3637
GIT_INLINE(int) git_config_backend_open(git_config_backend *cfg, unsigned int level, const git_repository *repo)
3738
{

src/config_mem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static void config_memory_free(git_config_backend *_backend)
186186
git__free(backend);
187187
}
188188

189-
int git_config_backend_from_string(git_config_backend **out, const char *cfg)
189+
int git_config_backend_from_string(git_config_backend **out, const char *cfg, size_t len)
190190
{
191191
config_memory_backend *backend;
192192

@@ -198,7 +198,7 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg)
198198
return -1;
199199
}
200200

201-
if (git_buf_sets(&backend->cfg, cfg) < 0) {
201+
if (git_buf_put(&backend->cfg, cfg, len) < 0) {
202202
git_config_entries_free(backend->entries);
203203
git__free(backend);
204204
return -1;

tests/config/memory.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void assert_config_contains_all(git_config_backend *backend,
6161

6262
static void setup_backend(const char *cfg)
6363
{
64-
cl_git_pass(git_config_backend_from_string(&backend, cfg));
64+
cl_git_pass(git_config_backend_from_string(&backend, cfg, strlen(cfg)));
6565
cl_git_pass(git_config_backend_open(backend, 0, NULL));
6666
}
6767

@@ -85,9 +85,10 @@ void test_config_memory__simple(void)
8585

8686
void test_config_memory__malformed_fails_to_open(void)
8787
{
88-
cl_git_pass(git_config_backend_from_string(&backend,
88+
const char *cfg =
8989
"[general\n"
90-
"foo=bar\n"));
90+
"foo=bar\n";
91+
cl_git_pass(git_config_backend_from_string(&backend, cfg, strlen(cfg)));
9192
cl_git_fail(git_config_backend_open(backend, 0, NULL));
9293
}
9394

0 commit comments

Comments
 (0)