pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkg/48318



The following reply was made to PR pkg/48318; it has been noted by GNATS.

From: David Holland <dholland-pbugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: pkg/48318
Date: Sat, 21 Dec 2013 18:49:16 +0000

 On Wed, Dec 18, 2013 at 11:35:01PM +0000, Patrick Welche wrote:
  >  I was about to create an upstream bug for this, but then I saw:
  >  
  >  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
  >  page 309 (327th of document):
  >  
  >     "If the format is exhausted while arguments remain, the excess
  >      arguments are evaluated (as always) but are otherwise ignored."
  >  
  >  So, amazingly, that code seems to be legal. Any thoughts from the
  >  language lawyers?
 
 It is legal, but so is
 
    printf("hello\n", "world\n");
 
 and many compilers correctly warn about or reject this.
 
 The correct way to write printfs like this is
 
    g_log(log_domain, G_LOG_LEVEL_ERROR,
          "file %s: line %d (%s): %s%s%s",
          file, line, pretty_function,
          expression ? "assertion failed: (" : "should not be reached",
          expression ? expression : "",
          expression ? ")" : "");
 
 or, less tidily,
 
    g_log(log_domain, G_LOG_LEVEL_ERROR,
          expression ? "file %s: line %d (%s): assertion failed: (%s)"
                     : "file %s: line %d (%s): should not be reached%s",
          file, line, pretty_function,
          expression ? expression : "");
 
 -- 
 David A. Holland
 dholland%netbsd.org@localhost
 


Home | Main Index | Thread Index | Old Index