Notes
This function is in beta test. Please help improve it in the issues
here.
/in/hw7.c:256:15: runtime error: index 100 out of bounds for type 'borrows [100]' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /in/hw7.c:256:15 in ================================================================= ==2003==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff1583ce20 at pc 0x000000518294 bp 0x7fff157a2050 sp 0x7fff157a2048 READ of size 4 at 0x7fff1583ce20 thread T0 #0 0x518293 (/out/package/hw7+0x518293) #1 0x7fe1534c6b96 (/lib/x86_64-linux-gnu/libc.so.6+0x21b96) #2 0x41c9d9 (/out/package/hw7+0x41c9d9) Address 0x7fff1583ce20 is located in stack of thread T0 at offset 634144 in frame #0 0x514f7f (/out/package/hw7+0x514f7f) This frame has 13 object(s): [32, 634040) 'library' <== Memory access at offset 634144 overflows this variable [634304, 634560) 'cmd' [634624, 634880) 'title' [634944, 635200) 'id' [635264, 635520) 'name' [635584, 635840) 'id44' [635904, 636160) 'id88' [636224, 636480) 'title133' [636544, 636800
Hints
Your answer may be identical to the JOJ answer in the first several lines.
However, the main problem you meet now is Runtime Error. And the exit code of your program is 1, which should be 0.
Please double check your code to solve this problem and try again.
Your Answer
JOJ Answer
Welcome to the library management system, please type your commands. > book1 added to the system. > book12 added to the system. > book123 added to the system. > book1 added to the system. > book5 added to the system. > name1 added to the system. > name2 added to the system. > name3 added to the system. > 1 book1 on shelf 12 book12 on shelf 123 book123 on shelf 1234 book1 on shelf 12345 book5 on shelf > 1 name1 22 name2 333 name3 > 123 book123 on shelf > 1 book1 on shelf 1234 book1 on shelf > 12 book12 on shelf > 12 book12 on shelf > Success! book12 is borrowed by name1. > Book borrowed by name1: 12 book12 > Book borrowed by name2: > Book borrowed by name3: > 12 book12 borrowed > 12 book12 borrowed > Fail! The book was borrowed by another customer. > 12 book12 borrowed > 12 book12 borrowed > Fail! The book was borrowed by another customer. > Book borrowed by name1: 12 book12 > Book borrowed by name2: > Book borrowed by name3: > 12 book12 borrowed > 12 book12 borrowed > Success! book123 is borrowed by name2. >