Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Compiler design in C? Date: Sat, 12 Nov 2016 14:33:52 -0800 Organization: None to speak of Lines: 55 Message-ID: References: <0915fef9-bb57-48b7-b98a-342f0e5ee39f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="f830fb76aec43d91603702f100a3d579"; logging-data="24495"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3haLozHYtjqkCOFlDw3tg" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:czYPpL0MoD4sM4kIN9x6UtvsjrM= sha1:oBILClNl6/Me89JKQQiJ29xmsgI= Xref: csiph.com comp.lang.c:96438 "Chris M. Thomasson" writes: > On 11/11/2016 4:11 PM, Keith Thompson wrote: [...] >> The use of "\r\n" suggests a misunderstanding about how the *scanf() >> functions work. > > The only reason why I used "\r\n" in fscanf to parse the secret key file > is to mirror the fprintf that creates them here: [snip] Whatever the reason, it's misleading. And why are you using "\r\n" in printf? On a Unix-like system, it will print "\r\n"; on Windows, it will probably print "\r\r\n". Unless out_file is opened in binary mode. Is it? [...] >> fscanf returns EOF (typically -1) only if "an input failure occurs >> before the first conversion (if any) has completed". > > Right. My code checks the number of conversions made and only reports > success if it is equal to FFE_SECRET_KEY_ARGS, defined as: > > #define FFE_SECRET_KEY_ARGS 13 > > FWIW, here is the entire function that parses secret key files, and uses > fscanf: [snip] >> Are you sure that in_file has been opened correctly? > > Yes. The code would have never got to the point where it wanted to parse > it if the in_file was not opened. That code can be found in the > ffe_cmdline_app_create function here: [snip] > It checks skey_file for NULL, and then passes it over to the > ffe_secret_key_parse_from_file function as the in_file parameter. But, > lcc returns -1 in the fscanf function, and my program sees that and does > not work by reporting an error. > > I am kind of at a loss about what to do about it. Well, you're going to need to figure out why fscanf() is failing. Try setting errno to 0 before the call and checking its value after (fscanf isn't required to set errno, but in many implementations it does). Try replacing the fscanf call with a much simpler one; if that succeeds, try doing a binary search to narrow down why your call fails and the simpler one doesn't. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"