Hi, I'm just starting to teach myself C++ and using Codewars to gain some experience.
I'm really stuck on a runtime error I got yesterday.
My code appears to be an adequate solution to the "Mumbling" Kata (C++), but I've clearly done something wrong that is causing runtime errors.
I believe this is some sort of memory / page fault, and perhaps I'm miss-using string Str initialization or manipulation?
It would be great if someone could tell me why I'm getting the runtime errors.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
class Accumul
{
public:
static std::string accum(const std::string &s)
{
size_t i, a, b, c=0;
static std::string str;
i=s.size();
for (a=0;a<i;a++)
{
s[a]<91 ? str[c] = s[a] : str[c] = (s[a]-32);
c++;
for (b=a;b>0;b--)
{
s[a]>91 ? str[c] = s[a] : str[c] = (s[a]+32);
c++;
}
if (a<(i-1)) str[c]='-';
c++;
}
return str.c_str();
}
};
/* Sample Tests
void testequal(std::string ans, std::string sol) {
Assert::That(ans, Equals(sol));
}
static void dotest(std::string s, std::string expected)
{
testequal(Accumul::accum(s), expected);
}
Describe(accum_Tests)
{
It(Fixed_Tests)
{
dotest("ZpglnRxqenU", "Z-Pp-Ggg-Llll-Nnnnn-Rrrrrr-Xxxxxxx-Qqqqqqqq-Eeeeeeeee-Nnnnnnnnnn-Uuuuuuuuuuu");
dotest("NyffsGeyylB", "N-Yy-Fff-Ffff-Sssss-Gggggg-Eeeeeee-Yyyyyyyy-Yyyyyyyyy-Llllllllll-Bbbbbbbbbbb");
}
};
*/
|
This is the output I'm getting:
Time: 2152ms Passed: 1 Failed: 0 Exit Code: 1
Test Results:
accum_Tests
Fixed_Tests
Test Passed
STDERR
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x00000042a691 bp 0x00000042aef0 sp 0x7ffda61d6c20 T1)
==1==The signal is caused by a READ memory access.
==1==Hint: address points to the zero page.
==1==WARNING: invalid path to external symbolizer!
==1==WARNING: Failed to use and restart external symbolizer!
#0 0x42a690 (/workspace/test+0x42a690)
#1 0x4256a2 (/workspace/test+0x4256a2)
#2 0x7fa052b92bf6 (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
#3 0x404609 (/workspace/test+0x404609)
UndefinedBehaviorSanitizer can not provide additional info.
==1==ABORTING