summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorSteve Murphy <murf@digium.com>2008-11-18 18:07:55 +0000
committerSteve Murphy <murf@digium.com>2008-11-18 18:07:55 +0000
commitf68bfa4ff35b6088f736def9e0c98ac181b1238b (patch)
tree157d0348db57eb438fc0caf51af1d808948b7797 /main
parent1287486dbf287fd0baac26fd6e4831c41434ea77 (diff)
(closes issue #13420)
Reported by: alex70 Patches: 13420.13539.patch uploaded by murf (license 17) Tested by: murf, awk This fixes two problems: a spurious linefeed insertion probably left over from pre-precomment times. Only generated when category had no previous comments. The other problem: Insertions could get the line-numbering out of whack and generate negative line numbers, causing chunks of line numbers to be emitted, on the scale of the number of lines up to that point in the file. In such cases, abort the looping, and all is well. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@157302 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/config.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/main/config.c b/main/config.c
index 6726b7ac2..f5fa9cd91 100644
--- a/main/config.c
+++ b/main/config.c
@@ -1552,7 +1552,10 @@ static void insert_leading_blank_lines(FILE *fp, struct inclfile *fi, struct ast
stored in the precomments, but not printed back out.
I did have to make sure that comments following
the ;! header comments were not also deleted in the process */
- for (i=fi->lineno;i<lineno - precomment_lines; i++) {
+ if (lineno - precomment_lines - fi->lineno < 0) { /* insertions can mess up the line numbering and produce negative numbers that mess things up */
+ return;
+ }
+ for (i=fi->lineno; i<lineno - precomment_lines; i++) {
fprintf(fp,"\n");
}
fi->lineno = lineno+1; /* Advance the file lineno */
@@ -1641,7 +1644,7 @@ int ast_config_text_file_save(const char *configfile, const struct ast_config *c
}
}
}
-
+
insert_leading_blank_lines(f, fi, cat->precomments, cat->lineno);
/* Dump section with any appropriate comment */
for (cmt = cat->precomments; cmt; cmt=cmt->next) {
@@ -1655,8 +1658,6 @@ int ast_config_text_file_save(const char *configfile, const struct ast_config *c
if (cmtp)
fprintf(f,"%s", cmtp);
}
- if (!cat->precomments)
- fprintf(f,"\n");
fprintf(f, "[%s]", cat->name);
if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) {
fprintf(f, "(");