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
fdc637c4
Commit
fdc637c4
authored
Aug 12, 2012
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check prettify message output buffer after cleanup
This makes the message prettify buffer length check accurate.
parent
c9d78bde
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
4 deletions
+66
-4
src/message.c
+6
-4
tests-clar/object/commit/commitstagedfile.c
+60
-0
No files found.
src/message.c
View file @
fdc637c4
...
...
@@ -63,10 +63,7 @@ int git_message_prettify(char *message_out, size_t buffer_size, const char *mess
{
git_buf
buf
=
GIT_BUF_INIT
;
if
(
strlen
(
message
)
+
1
>
buffer_size
)
{
/* We have to account for a potentially missing \n */
giterr_set
(
GITERR_INVALID
,
"Buffer too short to hold the cleaned message"
);
return
-
1
;
}
assert
(
message_out
&&
buffer_size
);
*
message_out
=
'\0'
;
...
...
@@ -75,6 +72,11 @@ int git_message_prettify(char *message_out, size_t buffer_size, const char *mess
return
-
1
;
}
if
(
buf
.
size
+
1
>
buffer_size
)
{
/* +1 for NUL byte */
giterr_set
(
GITERR_INVALID
,
"Buffer too short to hold the cleaned message"
);
return
-
1
;
}
git_buf_copy_cstr
(
message_out
,
buffer_size
,
&
buf
);
git_buf_free
(
&
buf
);
...
...
tests-clar/object/commit/commitstagedfile.c
View file @
fdc637c4
...
...
@@ -128,3 +128,63 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
git_tree_free
(
tree
);
git_index_free
(
index
);
}
void
test_object_commit_commitstagedfile__message_prettify
(
void
)
{
char
buffer
[
100
];
cl_git_pass
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
""
,
0
));
cl_assert_equal_s
(
buffer
,
""
);
cl_git_pass
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
""
,
1
));
cl_assert_equal_s
(
buffer
,
""
);
cl_git_pass
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"Short"
,
0
));
cl_assert_equal_s
(
buffer
,
"Short
\n
"
);
cl_git_pass
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"Short"
,
1
));
cl_assert_equal_s
(
buffer
,
"Short
\n
"
);
cl_git_pass
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"This is longer
\n
And multiline
\n
# with some comments still in
\n
"
,
0
));
cl_assert_equal_s
(
buffer
,
"This is longer
\n
And multiline
\n
# with some comments still in
\n
"
);
cl_git_pass
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"This is longer
\n
And multiline
\n
# with some comments still in
\n
"
,
1
));
cl_assert_equal_s
(
buffer
,
"This is longer
\n
And multiline
\n
"
);
/* try out overflow */
cl_git_pass
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"12345678"
,
0
));
cl_assert_equal_s
(
buffer
,
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"12345678
\n
"
);
cl_git_pass
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"12345678
\n
"
,
0
));
cl_assert_equal_s
(
buffer
,
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"12345678
\n
"
);
cl_git_fail
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"123456789"
,
0
));
cl_git_fail
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"123456789
\n
"
,
0
));
cl_git_fail
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
,
0
));
cl_git_fail
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890""x"
,
0
));
cl_git_pass
(
git_message_prettify
(
buffer
,
sizeof
(
buffer
),
"1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890
\n
"
"# 1234567890"
"1234567890"
"1234567890"
"1234567890"
"1234567890
\n
"
"1234567890"
,
1
));
}
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