do_who warnings

Posted by Ithildin on Tue 30 May 2006 02:24 AM — 6 posts, 20,626 views.

USA #0
I'm switching up the do_who code to look a little better. I'm using smaugfuss 1.7 When I compiled I got these two errors and I don't know how to fix them:

make -s smaug
  Compiling o/act_info.o....
act_info.c: In function `do_who':
act_info.c:2960: warning: format not a string literal and no format arguments
act_info.c:2984: warning: format not a string literal and no format arguments
make[1]: *** [o/act_info.o] Error 1
make: *** [all] Error 2


Here's the two lines:

for ( cur_who = first_imm; cur_who; cur_who = next_who )
    {
      if ( !ch )
        fprintf( whoout, cur_who->text );  <--------Offending line
      else
        send_to_pager( cur_who->text, ch );
      next_who = cur_who->next;
      DISPOSE( cur_who->text );
      DISPOSE( cur_who );
	  } 


and

for ( cur_who = first_mortal; cur_who; cur_who = next_who )
    {
      if ( !ch )
        fprintf( whoout, cur_who->text ); <-------------Second Offending Line
      else
        send_to_pager( cur_who->text, ch );
      next_who = cur_who->next;
      DISPOSE( cur_who->text );
      DISPOSE( cur_who ); 
    } 


What's wrong with those two lines?
USA #1
got it fixed.
USA #2
For reference, the problem is that it wants a string explaining the format, not a straight string. It's a little odd that it's requiring that, even if it makes sense in some situations. (It means that it would, for example, incorrect warn about a format string being contained in a runtime-defined string.)
Australia Forum Administrator #3
Quote:

When I compiled I got these two errors ...


These are warnings, not errors.

I think it wants to check the arguments for you. For example, if you did:


int i;
fprintf (whoout, "%s", i );


Then it can say that "i" is an integer and not a string.

In your case you are supplying a single argument, so it is wondering why you are using fprintf in the first place.
Amended on Tue 30 May 2006 05:39 AM by Nick Gammon
USA #4
Ah, you're right, it probably wouldn't complain if you gave it arguments with a runtime string as a format specifier.
USA #5
Yea, that's what it was. I was missing the "%s"