diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-10 01:50:58 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-10 01:50:58 +0100 |
commit | 478ac90f2c55cf66c13aa9805bde69bc705647c3 (patch) | |
tree | 94ccadc0273a637eac48fcc764336baa8a675461 | |
parent | ad12ab439b5d0383ac4ebe41479b694df0b2e70d (diff) | |
download | busybox-w32-478ac90f2c55cf66c13aa9805bde69bc705647c3.tar.gz busybox-w32-478ac90f2c55cf66c13aa9805bde69bc705647c3.tar.bz2 busybox-w32-478ac90f2c55cf66c13aa9805bde69bc705647c3.zip |
cut: allocate "printed" only if OPT_CHAR or OPT_BYTE
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/cut.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index e81c6fecb..ca2408f97 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -101,12 +101,13 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
101 | 101 | ||
102 | /* set up a list so we can keep track of what's been printed */ | 102 | /* set up a list so we can keep track of what's been printed */ |
103 | int linelen = strlen(line); | 103 | int linelen = strlen(line); |
104 | char *printed = xzalloc(linelen + 1); | ||
105 | char *orig_line = line; | 104 | char *orig_line = line; |
106 | unsigned cl_pos = 0; | 105 | unsigned cl_pos = 0; |
107 | 106 | ||
108 | /* cut based on chars/bytes XXX: only works when sizeof(char) == byte */ | 107 | /* cut based on chars/bytes XXX: only works when sizeof(char) == byte */ |
109 | if (option_mask32 & (OPT_CHAR | OPT_BYTE)) { | 108 | if (option_mask32 & (OPT_CHAR | OPT_BYTE)) { |
109 | char *printed = xzalloc(linelen + 1); | ||
110 | |||
110 | /* print the chars specified in each cut list */ | 111 | /* print the chars specified in each cut list */ |
111 | for (; cl_pos < nlists; cl_pos++) { | 112 | for (; cl_pos < nlists; cl_pos++) { |
112 | int spos; | 113 | int spos; |
@@ -120,6 +121,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
120 | } | 121 | } |
121 | } | 122 | } |
122 | } | 123 | } |
124 | free(printed); | ||
123 | } else if (*delim == '\n') { /* cut by lines */ | 125 | } else if (*delim == '\n') { /* cut by lines */ |
124 | int spos = cut_lists[cl_pos].startpos; | 126 | int spos = cut_lists[cl_pos].startpos; |
125 | 127 | ||
@@ -214,9 +216,8 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
214 | putchar('\n'); | 216 | putchar('\n'); |
215 | next_line: | 217 | next_line: |
216 | linenum++; | 218 | linenum++; |
217 | free(printed); | ||
218 | free(orig_line); | 219 | free(orig_line); |
219 | } | 220 | } /* while (got line) */ |
220 | #undef opt_REGEX | 221 | #undef opt_REGEX |
221 | } | 222 | } |
222 | 223 | ||