Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
  • you must dynamically allocate memory

  • *** Error in `./test': free(): invalid pointer: 0x00000000006031c0 ***
    ======= Backtrace: =========
    /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fcddf35b7e5]
    /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fcddf36437a]
    /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fcddf36853c]
    ./test[0x40129f]
    /usr/lib/libcriterion.so(criterion_internal_test_main+0xaf)[0x7fcddfbaa29f]
    ./test[0x400fc8]
    /usr/lib/libcriterion.so(run_test_child+0xb0)[0x7fcddfba8100]
    /usr/lib/libcriterion.so(run_worker+0x36)[0x7fcddfba9986]
    /usr/lib/libcriterion.so(spawn_test_worker+0x140)[0x7fcddfba9b00]
    /usr/lib/libcriterion.so(+0x9487)[0x7fcddfba9487]
    /usr/lib/libcriterion.so(run_next_test+0x16c)[0x7fcddfba966c]
    /usr/lib/libcriterion.so(criterion_run_all_tests+0x23e)[0x7fcddfba863e]
    /usr/lib/libcriterion.so(main+0x30)[0x7fcddfba7720]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fcddf304830]
    ./test[0x400ed9]
    ======= Memory map: ========
    00400000-00403000 r-xp 00000000 08:01 428982 /home/codewarrior/test
    00602000-00603000 r--p 00002000 08:01 428982 /home/codewarrior/test
    00603000-00604000 rw-p 00003000 08:01 428982 /home/codewarrior/test
    01bc2000-01be3000 rw-p 00000000 00:00 0 [heap]
    7fcdd8000000-7fcdd8021000 rw-p 00000000 00:00 0
    7fcdd8021000-7fcddc000000 ---p 00000000 00:00 0
    7fcdde455000-7fcdde46b000 r-xp 00000000 08:01 8023225 /lib/x86_64-linux-gnu/libgcc_s.so.1
    7fcdde46b000-7fcdde66a000 ---p 00016000 08:01 8023225 /lib/x86_64-linux-gnu/libgcc_s.so.1
    7fcdde66a000-7fcdde66b000 rw-p 00015000 08:01 8023225 /lib/x86_64-linux-gnu/libgcc_s.so.1
    7fcdde66b000-7fcdde66c000 ---p 00000000 00:00 0
    7fcdde66c000-7fcddee6c000 rwxp 00000000 00:00 0
    7fcddee6c000-7fcddeeda000 r-xp 00000000 08:01 8023823 /lib/x86_64-linux-gnu/libpcre.so.3.13.2
    7fcddeeda000-7fcddf0da000 ---p 0006e000 08:01 8023823 /lib/x86_64-linux-gnu/libpcre.so.3.13.2
    7fcddf0da000-7fcddf0db000 r--p 0006e000 08:01 8023823 /lib/x86_64-linux-gnu/libpcre.so.3.13.2
    7fcddf0db000-7fcddf0dc000 rw-p 0006f000 08:01 8023823 /lib/x86_64-linux-gnu/libpcre.so.3.13.2
    7fcddf0dc000-7fcddf0e3000 r-xp 00000000 08:01 8023855 /lib/x86_64-linux-gnu/librt-2.23.so
    7fcddf0e3000-7fcddf2e2000 ---p 00007000 08:01 8023855 /lib/x86_64-linux-gnu/librt-2.23.so
    7fcddf2e2000-7fcddf2e3000 r--p 00006000 08:01 8023855 /lib/x86_64-linux-gnu/librt-2.23.so
    7fcddf2e3000-7fcddf2e4000 rw-p 00007000 08:01 8023855 /lib/x86_64-linux-gnu/librt-2.23.so
    7fcddf2e4000-7fcddf4a4000 r-xp 00000000 08:01 8022988 /lib/x86_64-linux-gnu/libc-2.23.so
    7fcddf4a4000-7fcddf6a4000 ---p 001c0000 08:01 8022988 /lib/x86_64-linux-gnu/libc-2.23.so
    7fcddf6a4000-7fcddf6a8000 r--p 001c0000 08:01 8022988 /lib/x86_64-linux-gnu/libc-2.23.so
    7fcddf6a8000-7fcddf6aa000 rw-p 001c4000 08:01 8022988 /lib/x86_64-linux-gnu/libc-2.23.so
    7fcddf6aa000-7fcddf6ae000 rw-p 00000000 00:00 0
    7fcddf6ae000-7fcddf6c6000 r-xp 00000000 08:01 8023826 /lib/x86_64-linux-gnu/libpthread-2.23.so
    7fcddf6c6000-7fcddf8c5000 ---p 00018000 08:01 8023826 /lib/x86_64-linux-gnu/libpthread-2.23.so
    7fcddf8c5000-7fcddf8c6000 r--p 00017000 08:01 8023826 /lib/x86_64-linux-gnu/libpthread-2.23.so
    7fcddf8c6000-7fcddf8c7000 rw-p 00018000 08:01 8023826 /lib/x86_64-linux-gnu/libpthread-2.23.so
    7fcddf8c7000-7fcddf8cb000 rw-p 00000000 00:00 0
    7fcddf8cb000-7fcddf99a000 r-xp 00000000 08:01 529467 /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6
    7fcddf99a000-7fcddfb9a000 ---p 000cf000 08:01 529467 /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6
    7fcddfb9a000-7fcddfb9d000 r--p 000cf000 08:01 529467 /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6
    7fcddfb9d000-7fcddfb9f000 rw-p 000d2000 08:01 529467 /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6
    7fcddfb9f000-7fcddfba0000 rw-p 00000000 00:00 0
    7fcddfba0000-7fcddfbb7000 r-xp 00000000 08:01 1052061 /usr/lib/libcriterion.so
    7fcddfbb7000-7fcddfdb7000 ---p 00017000 08:01 1052061 /usr/lib/libcriterion.so
    7fcddfdb7000-7fcddfdb8000 r--p 00017000 08:01 1052061 /usr/lib/libcriterion.so
    7fcddfdb8000-7fcddfdb9000 rw-p 00018000 08:01 1052061 /usr/lib/libcriterion.so
    7fcddfdb9000-7fcddfdbc000 r-xp 00000000 08:01 8023161 /lib/x86_64-linux-gnu/libdl-2.23.so
    7fcddfdbc000-7fcddffbb000 ---p 00003000 08:01 8023161 /lib/x86_64-linux-gnu/libdl-2.23.so
    7fcddffbb000-7fcddffbc000 r--p 00002000 08:01 8023161 /lib/x86_64-linux-gnu/libdl-2.23.so
    7fcddffbc000-7fcddffbd000 rw-p 00003000 08:01 8023161 /lib/x86_64-linux-gnu/libdl-2.23.so
    7fcddffbd000-7fcde01d7000 r-xp 00000000 08:01 528955 /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
    7fcde01d7000-7fcde03d6000 ---p 0021a000 08:01 528955 /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
    7fcde03d6000-7fcde03f2000 r--p 00219000 08:01 528955 /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
    7fcde03f2000-7fcde03fe000 rw-p 00235000 08:01 528955 /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
    7fcde03fe000-7fcde0401000 rw-p 00000000 00:00 0
    7fcde0401000-7fcde0509000 r-xp 00000000 08:01 8023347 /lib/x86_64-linux-gnu/libm-2.23.so
    7fcde0509000-7fcde0708000 ---p 00108000 08:01 8023347 /lib/x86_64-linux-gnu/libm-2.23.so
    7fcde0708000-7fcde0709000 r--p 00107000 08:01 8023347 /lib/x86_64-linux-gnu/libm-2.23.so
    7fcde0709000-7fcde070a000 rw-p 00108000 08:01 8023347 /lib/x86_64-linux-gnu/libm-2.23.so
    7fcde070a000-7fcde0730000 r-xp 00000000 08:01 8022887 /lib/x86_64-linux-gnu/ld-2.23.so
    7fcde091f000-7fcde0926000 rw-p 00000000 00:00 0
    7fcde092e000-7fcde092f000 rw-p 00000000 00:00 0
    7fcde092f000-7fcde0930000 r--p 00025000 08:01 8022887 /lib/x86_64-linux-gnu/ld-2.23.so
    7fcde0930000-7fcde0931000 rw-p 00026000 08:01 8022887 /lib/x86_64-linux-gnu/ld-2.23.so
    7fcde0931000-7fcde0932000 rw-p 00000000 00:00 0
    7ffd1f829000-7ffd1f84a000 rwxp 00000000 00:00 0 [stack]
    7ffd1f9ac000-7ffd1f9af000 r--p 00000000 00:00 0 [vvar]
    7ffd1f9af000-7ffd1f9b1000 r-xp 00000000 00:00 0 [vdso]
    ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]

  • --Log--
    PASS: 0
    PASS: 0.0
    PASS: 0.1
    PASS: 0.2
    PASS: 0.3
    submitted = "elppa"
    expected = "elppa"
    --Log ends here--

  • Test(Sample_Tests, should_pass_all_the_tests_provided) {
      printf("PASS: 0\n");
      {
          printf("PASS: 0.0\n");
        const char* test_str = "apple";
          printf("PASS: 0.1\n");
        const char* expected = "elppa";
          printf("PASS: 0.2\n");
        char* submitted = reverseWords(test_str);
          printf("PASS: 0.3\n");
          printf("submitted = \"%s\"\n",submitted);
          printf("expected  = \"%s\"\n",expected);
        cr_assert_str_eq(expected, submitted,
                        "Expected:\n\"%s\"\n\nSubmitted:\n\"%s\"\n\n", expected, submitted); //Something wrong here?
          printf("PASS: 0.4\n");
        free(submitted); submitted = NULL;
          printf("PASS: 0.5\n");
      }
    
  • Hey my function gets the "apple" example right perfectly but it stops during cr_assert_str_eq() and returns a pointer error. What's wrong? I tested my code for multiple cases and it works for all, including spaces, double spaces and checking for extra or missing space at the end of the string too.

  • Sorry didnt think I had to since I'm in the solutions section

  • This comment is hidden because it contains spoiler information about the solution

  • This comment is hidden because it contains spoiler information about the solution

  • I've tested this several times and the RANDOM character string tests are befuddling.
    EXPECTED & SUBMITTED look the same BUT
    If I look at copy and paste the exected results I see some embedded control characters that dont appear "\u007f"

  • Use markdown formatting to post code and retain spaces and format so we can see the exact error message. That test input is a string with all spaces as the test name suggest, so it seems your function is not returning it right.

  • Java:
    allSpaces Test
    expected:< []> but was:< [ ]>
    What does it mean?

  • RTFM...

  • expected = "a b c d" Is that even right?

  • Oh, thanks! Didn't even realize :D

  • It's a problem with your code, try it with this in the sample tests:

    assertEquals("si sihT sihT", Kata.reverseWords("is This This"));
    

    Not a kata issue.

  • Loading more items...