Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions generate/templates/manual/patches/convenient_patches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void GitPatch::ConvenientFromDiffWorker::Execute() {

if (nextPatch != NULL) {
baton->out->push_back(createFromRaw(nextPatch));
patchesToBeFreed.push_back(nextPatch);
}
}

Expand Down
12 changes: 6 additions & 6 deletions generate/templates/manual/src/convenient_patch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ PatchData *createFromRaw(git_patch *raw) {
hunkData->lines = new std::vector<git_diff_line *>;
hunkData->lines->reserve(hunkData->numLines);


static const int noNewlineStringLength = 29;
bool EOFFlag = false;
for (unsigned int j = 0; j < hunkData->numLines; ++j) {
git_diff_line *storeLine = (git_diff_line *)malloc(sizeof(git_diff_line));
Expand All @@ -79,9 +79,9 @@ PatchData *createFromRaw(git_patch *raw) {
// calculate strlen only once for the first line of the first hunk.
int calculatedContentLength = strlen(line->content);
if (
calculatedContentLength > 29 &&
calculatedContentLength > noNewlineStringLength &&
!strcmp(
&line->content[calculatedContentLength - 29],
&line->content[calculatedContentLength - noNewlineStringLength],
"\n\\ No newline at end of file\n"
)) {
EOFFlag = true;
Expand All @@ -96,10 +96,10 @@ PatchData *createFromRaw(git_patch *raw) {
storeLine->content_offset = line->content_offset;
char * transferContent;
if (EOFFlag) {
transferContent = (char *)malloc(storeLine->content_len + 30);
transferContent = (char *)malloc(storeLine->content_len + noNewlineStringLength + 1);
memcpy(transferContent, line->content, storeLine->content_len);
memcpy(transferContent + storeLine->content_len, "\n\\ No newline at end of file\n", 29);
transferContent[storeLine->content_len + 29] = '\0';
memcpy(transferContent + storeLine->content_len, "\n\\ No newline at end of file\n", noNewlineStringLength);
transferContent[storeLine->content_len + noNewlineStringLength] = '\0';
} else {
transferContent = (char *)malloc(storeLine->content_len + 1);
memcpy(transferContent, line->content, storeLine->content_len);
Expand Down