| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Message
| Well, a quick test with gdb reveals the problem is indeed where you thought. I only had to type in 3 things to establish that (bt, f 4, list)...
(gdb) bt
#0 0x4207a6db in strlen () from /lib/tls/libc.so.6
#1 0x420477ed in vfprintf () from /lib/tls/libc.so.6
#2 0x420645fc in vsprintf () from /lib/tls/libc.so.6
#3 0x080c0468 in ch_printf(char_data*, char*, ...) (ch=0x857a9f0,
fmt=0x8195520 "It is %d o'clock %s, %s of , week, the Month of %s.\n\rThe mud started up at: %s\rThe system time (E.S.T.): %s\rNext Reboot is set for: %s\r") at comm.c:2962
#4 0x08059d83 in do_time(char_data*, char*) (ch=0x857a9f0, argument=0xbfffe614 "") at act_info.c:1789
#5 0x08100dbb in interpret(char_data*, char*) (ch=0x857a9f0, argument=0xbfffe614 "") at interp.c:738
#6 0x080baebd in game_loop() () at comm.c:738
#7 0x080ba27e in main (argc=1, argv=0xbfffeb14) at comm.c:322
#8 0x420156a4 in __libc_start_main () from /lib/tls/libc.so.6
(gdb) f 4
#4 0x08059d83 in do_time(char_data*, char*) (ch=0x857a9f0, argument=0xbfffe614 "") at act_info.c:1789
1789 ch_printf( ch,
(gdb) list
1784 else if ( day % 10 == 2 ) suf = "nd";
1785 else if ( day % 10 == 3 ) suf = "rd";
1786 else suf = "th";
1787
1788 set_char_color( AT_YELLOW, ch );
1789 ch_printf( ch,
1790 "It is %d o'clock %s, %s of , week, the Month of %s.\n\r"
// I changed this line to try and get
1791 // what I wanted to display. Probably goofed up.
1792 "The mud started up at: %s\r"
1793 "The system time (E.S.T.): %s\r"
1794 "Next Reboot is set for: %s\r",
1795
1796 (time_info.hour % 12 == 0) ? 12 : time_info.hour % 12,
1797 time_info.hour >= 12 ? "pm" : "am",
1798 day_name[day % 10], //Here, I changed the day from 7 to 10
1799 day, suf,
1800 month_name[time_info.month],
1801 str_boot_time,
1802 (char *) ctime( ¤t_time ),
1803 reboot_time
1804 );
1805
1806 return;
1807 }
Your problem is the printf string. To not have a crash the replacement things (%d, %s etc.) need to match up with what you are actually supplying.
Disregarding the other words, you are trying to get expanded:
%d %s %s %s %s %s %s
(ie. 1 number, 6 strings)
However what you are supplying is:
(number) (time_info.hour % 12 == 0) ? 12 : time_info.hour % 12,
(string) time_info.hour >= 12 ? "pm" : "am",
(string) day_name[day % 10], //Here, I changed the day from 7 to 10
(number) day,
(string) suf,
(string) month_name[time_info.month],
(string) str_boot_time,
(string) (char *) ctime( ¤t_time ),
(string) reboot_time
(ie. 1 number, 2 strings, 1 number, 6 strings)
Things have to agree, or it will crash. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|