mirror of
https://github.com/sheumann/hush.git
synced 2024-07-07 10:28:56 +00:00
Rewrite -c and -b processing to shrink code and eliminate buffer overrun.
This commit is contained in:
parent
6b8c550d88
commit
2e6c878763
@ -108,20 +108,10 @@ static void cut_file(FILE *file)
|
|||||||
for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
|
for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
|
||||||
/* cut based on chars/bytes */
|
/* cut based on chars/bytes */
|
||||||
if (part == 'c' || part == 'b') {
|
if (part == 'c' || part == 'b') {
|
||||||
int i;
|
chomp(line);
|
||||||
/* a valid end position has been specified */
|
if (0 < endpos && endpos < strlen(line))
|
||||||
if (endpos > 0) {
|
line[endpos] = '\0';
|
||||||
for (i = startpos-1; i < endpos; i++) {
|
puts(line + startpos - 1);
|
||||||
fputc(line[i], stdout);
|
|
||||||
}
|
|
||||||
fputc('\n', stdout);
|
|
||||||
}
|
|
||||||
/* otherwise, just go to the end of the line */
|
|
||||||
else {
|
|
||||||
for (i = startpos-1; line[i]; i++) {
|
|
||||||
fputc(line[i], stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* cut based on fields */
|
/* cut based on fields */
|
||||||
else if (part == 'f') {
|
else if (part == 'f') {
|
||||||
|
18
cut.c
18
cut.c
@ -108,20 +108,10 @@ static void cut_file(FILE *file)
|
|||||||
for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
|
for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
|
||||||
/* cut based on chars/bytes */
|
/* cut based on chars/bytes */
|
||||||
if (part == 'c' || part == 'b') {
|
if (part == 'c' || part == 'b') {
|
||||||
int i;
|
chomp(line);
|
||||||
/* a valid end position has been specified */
|
if (0 < endpos && endpos < strlen(line))
|
||||||
if (endpos > 0) {
|
line[endpos] = '\0';
|
||||||
for (i = startpos-1; i < endpos; i++) {
|
puts(line + startpos - 1);
|
||||||
fputc(line[i], stdout);
|
|
||||||
}
|
|
||||||
fputc('\n', stdout);
|
|
||||||
}
|
|
||||||
/* otherwise, just go to the end of the line */
|
|
||||||
else {
|
|
||||||
for (i = startpos-1; line[i]; i++) {
|
|
||||||
fputc(line[i], stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* cut based on fields */
|
/* cut based on fields */
|
||||||
else if (part == 'f') {
|
else if (part == 'f') {
|
||||||
|
Loading…
Reference in New Issue
Block a user