Fix uninitialized variable in cmdargs and incorrect WEOF usage

This commit is contained in:
rexy712 2019-12-27 10:21:59 -08:00
parent ee4c9a6ea1
commit 3928766c6b
2 changed files with 4 additions and 5 deletions

View File

@ -25,7 +25,7 @@
#include <cstdlib> //atol
cmd_args::cmd_args(void)noexcept:
truecol(0), color(0), number(0), ends(0), squeeze(0), tabs(0), nonprinting(0), error(0), usage(0), version(0){}
truecol(0), color(0), number(0), ends(0), squeeze(0), tabs(0), nonprinting(0), treatbinary(0), error(0), usage(0), version(0){}
void cmd_args::clear_gnu_options(void){
number = PRINT_LINE_NEVER;
ends = squeeze = tabs = nonprinting = 0;

View File

@ -187,7 +187,7 @@ int real_print_files(const cmd_args& args){
if(args.treatbinary){
//Don't check if buf is empty because that's not how GNU cat handles Ctrl+D in middle of line
for(int in;(in = fgetc(stdin)) != WEOF;){
for(int in;(in = fgetc(stdin)) != EOF;){
p.print(static_cast<char>(in));
if(in == L'\n') //Only reset on newline to save print overhead
p.reset();
@ -210,13 +210,13 @@ int real_print_files(const cmd_args& args){
}
if(args.treatbinary){
if(args.nonprinting){
for(int in;(in = fgetc(fp)) != WEOF;){
for(int in;(in = fgetc(fp)) != EOF;){
char tmp[5];
nonprinting_notation(in, tmp);
p.print(tmp);
}
}else{
for(int in;(in = fgetc(fp)) != WEOF;)
for(int in;(in = fgetc(fp)) != EOF;)
p.print(static_cast<char>(in));
}
}else{
@ -276,6 +276,5 @@ int main(int argc, char** argv){
}else if(avail_colors == 256){
return print_files<basic_color_printer<256>>(args);
}
return 0;
}