Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
2e445cac
Commit
2e445cac
authored
Mar 30, 2011
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build_varname: allocate memory
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
parent
9a3c5e55
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
+15
-7
src/config.c
+15
-7
No files found.
src/config.c
View file @
2e445cac
...
@@ -596,16 +596,24 @@ static int config_parse(git_config *cfg_file)
...
@@ -596,16 +596,24 @@ static int config_parse(git_config *cfg_file)
return
error
;
return
error
;
}
}
static
const
char
*
build_varname
(
const
char
*
section
,
const
char
*
name
,
int
len
)
/*
* Gives $section.$name back, using only name_len chars from the name,
* which is useful so we don't have to copy the variable name twice.
* Don't forget to free the memory you get.
*/
static
char
*
build_varname
(
const
char
*
section
,
const
char
*
name
,
int
name_len
)
{
{
static
char
varname
[
1024
];
/* TODO: What's the longest we should allow? */
char
*
varname
;
int
section_len
,
ret
;
if
(
strlen
(
section
)
+
len
+
2
>
sizeof
(
varname
))
size_t
total_len
;
section_len
=
strlen
(
section
);
total_len
=
section_len
+
name_len
+
2
;
varname
=
malloc
(
total_len
);
if
(
varname
==
NULL
)
return
NULL
;
return
NULL
;
strcpy
(
varname
,
section
);
ret
=
snprintf
(
varname
,
total_len
,
"%s.%s"
,
section
,
name
);
strcat
(
varname
,
"."
);
strncat
(
varname
,
name
,
len
);
return
varname
;
return
varname
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment