• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X Crash Log

_Aion_

Nothing Else
Joined
Jan 19, 2010
Messages
400
Solutions
4
Reaction score
10
Location
Jequie,Bahia,Brazil
Hello. I'm trying put system market on my server. But i have this bug.
Code:
ProtocolGame::sendMarketBrowseOwnOffers (this=<optimized out>,
    buyOffers=..., sellOffers=...) at protocolgame.cpp:3621
        test2 = <incomplete type>
        segment2 = "mo"
        seglist2 = std::vector of length 1, capacity 1 = {"mo"}
        i = 16
        itt = <optimized out>
        test = <incomplete type>
        segment = "mo"
        seglist = std::vector of length 17, capacity 32 = {"poke#Mewtwo",
          "poke#Mewtwo", "ball#poke", "ball#poke", "reverseIcon#poke",
          "reverseIcon#poke", "happy#255", "hp#0", "blink#cd:1610383732",
          "blink#cd:1610383732", "move1#cd:1610383733", "move1#cd:1610383733",
          "move2#cd:1610383733", "move2#cd:1610383733", "move3#cd:1610383733",
          "move3#cd:1610383733", "mo"}
        item = <optimized out>
        it = <optimized out>
        end = <optimized out>
the code's get this atribute from items
Lua:
{"poke", "nick", "memory", "xHeldItem", "megaID", "copyName", "SmeargleID", "addon", "ball", "yHeldItem","reverseIcon","gender", "boost", "happy", "hp", "transBegin", "hunger", "transLeft", "transTurn", "transOutfit", "transName", "trans", "light", "blink", "move1", "move2", "move3", "move4", "move5", "move6", "move7", "move8", "move9", "move10", "move11", "move12", "ballorder", "hands", "aura", "burn", "burndmg", "poison", "poisondmg", "confuse", "sleep", "miss", "missSpell", "missEff", "fear", "fearSkill", "silence", "silenceEff", "stun", "stunEff", "stunSpell", "paralyze", "paralyzeEff", "slow", "slowEff", "leech", "leechdmg", "Buff1", "Buff2", "Buff3", "Buff1skill","Buff2skill", "Buff3skill", "control", "task", "lock"};

and he is my code
Game.cpp - Pastebin.com (https://pastebin.com/U7jbubXE)
Protocolgame.cpp - Pastebin.com (https://pastebin.com/xemXgfT8)

i think that isn't reading all attrribute, something that size of vector.
Can someone help fix?
 
Solution
Paste whole stack trace along with raised error, not just selected frame. (or at least raised error details and top frames)
Tell us from which line of your pastes is the one that raised an error.
Paste whole stack trace along with raised error, not just selected frame. (or at least raised error details and top frames)
Tell us from which line of your pastes is the one that raised an error.
 
Solution
Paste whole stack trace along with raised error, not just selected frame. (or at least raised error details and top frames)
Tell us from which line of your pastes is the one that raised an error.
BT FULL
Code:
0x00007ffff5820464 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt full
#0  0x00007ffff5820464 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#1  0x00000000005b43a8 in atoi (__nptr=<optimized out>)
    at /usr/include/stdlib.h:280
No locals.
#2  ProtocolGame::sendMarketBrowseOwnOffers (this=<optimized out>,
    buyOffers=..., sellOffers=...) at protocolgame.cpp:3621
        test2 = <incomplete type>
        segment2 = "mo"
        seglist2 = std::vector of length 1, capacity 1 = {"mo"}
        i = 16
        itt = <optimized out>
        test = <incomplete type>
        segment = "mo"
        seglist = std::vector of length 17, capacity 32 = {"poke#Mewtwo",
          "poke#Mewtwo", "ball#poke", "ball#poke", "reverseIcon#poke",
          "reverseIcon#poke", "happy#255", "hp#0", "blink#cd:1610383732",
          "blink#cd:1610383732", "move1#cd:1610383733", "move1#cd:1610383733",
          "move2#cd:1610383733", "move2#cd:1610383733", "move3#cd:1610383733",
          "move3#cd:1610383733", "mo"}
        item = <optimized out>
        it = <optimized out>
        end = <optimized out>
BT
Code:
#0  0x00007ffff5820464 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00000000005b43a8 in atoi (__nptr=<optimized out>) at /usr/include/stdlib.h:280
#2  ProtocolGame::sendMarketBrowseOwnOffers (this=<optimized out>, buyOffers=..., sellOffers=...) at protocolgame.cpp:3621
#3  0x000000000047cc5e in Player::sendMarketBrowseOwnOffers (sellOffers=..., buyOffers=..., this=0x7fffa968dad0) at player.h:669
#4  Game::playerBrowseMarketOwnOffers (this=0x8c0c40 <g_game>, playerId=<optimized out>) at game.cpp:6451
#5  0x00000000005c2873 in boost::_mfi::mf1<bool, Game, unsigned int>::operator() (a1=<optimized out>, p=<optimized out>, this=<optimized out>)
    at /usr/include/boost/bind/mem_fn_template.hpp:165
#6  boost::_bi::list2<boost::_bi::value<Game*>, boost::_bi::value<unsigned int> >::operator()<bool, boost::_mfi::mf1<bool, Game, unsigned int>, boost::_bi::list0> (a=<synthetic pointer>, f=..., this=<optimized out>) at /usr/include/boost/bind/bind.hpp:303
#7  boost::_bi::bind_t<bool, boost::_mfi::mf1<bool, Game, unsigned int>, boost::_bi::list2<boost::_bi::value<Game*>, boost::_bi::value<unsigned int> > >::operator() (this=<optimized out>) at /usr/include/boost/bind/bind_template.hpp:20
#8  boost::detail::function::void_function_obj_invoker0<boost::_bi::bind_t<bool, boost::_mfi::mf1<bool, Game, unsigned int>, boost::_bi::list2<boost::_bi::value<Game*>, boost::_bi::value<unsigned int> > >, void>::invoke (function_obj_ptr=...) at /usr/include/boost/function/function_template.hpp:159
#9  0x00000000005fd75e in boost::function0<void>::operator() (this=0x8df8a0) at /usr/include/boost/function/function_template.hpp:773
#10 Task::operator() (this=0x8df890) at tasks.h:34
#11 Dispatcher::dispatcherThread (p=0x8b25a0 <Dispatcher::getInstance()::dispatcher>) at tasks.cpp:73
#12 0x00000000005d80f4 in boost::_bi::list1<boost::_bi::value<void*> >::operator()<void (*)(void*), boost::_bi::list0> (a=<synthetic pointer>,
    f=<optimized out>, this=<optimized out>) at /usr/include/boost/bind/bind.hpp:253
#13 boost::_bi::bind_t<void, void (*)(void*), boost::_bi::list1<boost::_bi::value<void*> > >::operator() (this=<optimized out>)
    at /usr/include/boost/bind/bind_template.hpp:20
#14 boost::detail::thread_data<boost::_bi::bind_t<void, void (*)(void*), boost::_bi::list1<boost::_bi::value<void*> > > >::run (this=<optimized out>)
    at /usr/include/boost/thread/detail/thread.hpp:116
#15 0x00007ffff6cb95d5 in ?? () from /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.58.0
#16 0x00007ffff64576ba in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#17 0x00007ffff58ec4dd in clone () from /lib/x86_64-linux-gnu/libc.so.6
 
What is this line exactly?
protocolgame.cpp:3621

I can see that you have some executions of atoi in your function.
First of all, ensure that every part of this function works properly (retrieves the values you need etc). You can try to change frame in gdb and print local variables to check the values of some interesting variables (for example seglist[0] and seglist[1]).

Looks like there is a problem with values provided to atoi function.

somewhere here:
C++:
if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
    item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));

1. Ensure that seglist2 has 2 elements.
2. You probably don't need these casting to char* as c_str() already returns const char* type, which should fit in your case: (char*)seglist2[1].c_str()
3. std::isdigit is used wrongly here. It checks just a single character and what you do is strange:
std::isdigit(atoi((char*)seglist2[1].c_str()))
You change string to int and validate whether it is a digit. I think that it should raise some compilation warning but anyway might still work, but...
the only values that returns the truth for isdigit are following characters: 0123456789 which are ascii values from 48 to 57. It means that if seglist[1] is a string of value "48" it will return true, because:
  • first it is converted to int "48" -> 48 (int)
  • then casted to char (as isdigit takes char as an input variable). So 48 (int) will be treated as an ascii number -> 48 in ascii represents character '0'
  • '0' character is a digit so isdigit function will return true.

value "47" for example will return false as number 47 in ascii represents character '/'.

Assuming...
Probably atoi tries to convert some non numeric value and throws an error. If you cannot debug it using gdb, try to print all interesting values just before executing atoi to a console window. Consider using some function with better error handling as atoi according to atoi - C++ Reference (https://www.cplusplus.com/reference/cstdlib/atoi/) causes undefined behavior when it is unable to convert the value properly. They suggest to use strtol (stoi). Or simply ensure that your code will always provide the number to atoi.
 
This is my 3621 protocolgame.cpp
C++:
                    if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
                        item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
Can you fix this for me?
codes are in pastebin on first post
 
If you use tfs 0.3.6 then probably in tools.cpp you have function like isNumbers which returns true if string contains only digits. Following code should help.
C++:
if(isNumbers(seglist2[1])){
    item->setAttribute(seglist2[0], atoi(seglist2[1].c_str()));

If tools.h is not included then add the following line somewhere at the top of protocolgames.cpp file.
C++:
#include "tools.h"

If it won't help, then add some console printing right before the condition like in the code below. If the server crash then check the very last messages printed in console.
C++:
std::cout << "seglist2[0]: " << seglist2[0] << std::endl;
std::cout << "seglist2[1]: " << seglist2[1] << std::endl;
if(isNumbers(seglist2[1])){
    item->setAttribute(seglist2[0], atoi(seglist2[1].c_str()));
 
If you use tfs 0.3.6 then probably in tools.cpp you have function like isNumbers which returns true if string contains only digits. Following code should help.
C++:
if(isNumbers(seglist2[1])){
    item->setAttribute(seglist2[0], atoi(seglist2[1].c_str()));

If tools.h is not included then add the following line somewhere at the top of protocolgames.cpp file.
C++:
#include "tools.h"

If it won't help, then add some console printing right before the condition like in the code below. If the server crash then check the very last messages printed in console.
C++:
std::cout << "seglist2[0]: " << seglist2[0] << std::endl;
std::cout << "seglist2[1]: " << seglist2[1] << std::endl;
if(isNumbers(seglist2[1])){
    item->setAttribute(seglist2[0], atoi(seglist2[1].c_str()));
Thanks. I Will try

EDIT: add new value

Code:
seglist2[0]: poke
seglist2[1]: Mewtwo
seglist2[0]: poke
seglist2[1]: Mewtwo
seglist2[0]: ball
seglist2[1]: poke
seglist2[0]: ball
seglist2[1]: poke
seglist2[0]: reverseIcon
seglist2[1]: poke
seglist2[0]: reverseIcon
seglist2[1]: poke
seglist2[0]: happy
seglist2[1]: 255
seglist2[0]: hp
seglist2[1]: 0
seglist2[0]: blink
seglist2[1]: cd:1610383732
seglist2[0]: blink
seglist2[1]: cd:1610383732
seglist2[0]: move1
seglist2[1]: cd:1610383733
seglist2[0]: move1
seglist2[1]: cd:1610383733
seglist2[0]: move2
seglist2[1]: cd:1610383733
seglist2[0]: move2
seglist2[1]: cd:1610383733
seglist2[0]: move3
seglist2[1]: cd:1610383733
seglist2[0]: move3
seglist2[1]: cd:1610383733
Segmentation fault (core dumped)

@esigma94

 
Last edited:
Ok, paste new stack trace. Another error should be raised.
And post updated code.
Code:
seglist2[0]: poke
seglist2[1]: Mewtwo
seglist2[0]: poke
seglist2[1]: Mewtwo
seglist2[0]: ball
seglist2[1]: poke
seglist2[0]: ball
seglist2[1]: poke
seglist2[0]: reverseIcon
seglist2[1]: poke
seglist2[0]: reverseIcon
seglist2[1]: poke
seglist2[0]: happy
seglist2[1]: 255
seglist2[0]: hp
seglist2[1]: 0
seglist2[0]: blink
seglist2[1]: cd:1610383732
seglist2[0]: blink
seglist2[1]: cd:1610383732
seglist2[0]: move1
seglist2[1]: cd:1610383733
seglist2[0]: move1
seglist2[1]: cd:1610383733
seglist2[0]: move2
seglist2[1]: cd:1610383733
seglist2[0]: move2
seglist2[1]: cd:1610383733
seglist2[0]: move3
seglist2[1]: cd:1610383733
seglist2[0]: move3
seglist2[1]: cd:1610383733

Thread 2 "theforgottenser" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff2642700 (LWP 1974)]
0x00007ffff5820464 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt full
#0  0x00007ffff5820464 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#1  0x00000000005b42b9 in atoi (__nptr=<optimized out>)
    at /usr/include/stdlib.h:280
No locals.
#2  ProtocolGame::sendMarketBrowseOwnOffers (this=<optimized out>,
    buyOffers=..., sellOffers=...) at protocolgame.cpp:3642
        test2 = <incomplete type>
        segment2 = "mo"
        seglist2 = std::vector of length 1, capacity 1 = {"mo"}
        i = 16
        itt = <optimized out>
        test = <incomplete type>
        segment = "mo"
        seglist = std::vector of length 17, capacity 32 = {"poke#Mewtwo",
          "poke#Mewtwo", "ball#poke", "ball#poke", "reverseIcon#poke",
          "reverseIcon#poke", "happy#255", "hp#0", "blink#cd:1610383732",
          "blink#cd:1610383732", "move1#cd:1610383733", "move1#cd:1610383733",
          "move2#cd:1610383733", "move2#cd:1610383733", "move3#cd:1610383733",
          "move3#cd:1610383733", "mo"}
        item = <optimized out>
        it = <optimized out>
        end = <optimized out>
---Type <return> to continue, or q <return> to quit---

i think that size of vector is low for much value... but i dont know how increase this value
 
seglist2 = std::vector of length 1, capacity 1 = {"mo"}
looks like seglist2 contains only 1 element, so you are not able to access seglist2[1] -> segfault.
The error is in another part of code this time.
before: protocolgame.cpp:3621
now: protocolgame.cpp:3642

Ensure that seglist2 contains 2 elements, otherwise print error to console.
C++:
if(seglist2.size() != 2){
    std::cout << "Error: seglist2 contains improper amount of segments (" << test2 << ")." << std::endl;
    continue;
}
else if(isNumbers(seglist2[1])){
    item->setAttribute(seglist2[0], atoi(seglist2[1].c_str()));

Also update all the other occurrences of the same code. If you did so, paste here new code then.

According to old code:
lines: 47, 89, 142, 184, 248 ....
 
I same code, only put this
Lua:
std::cout << "seglist2[0]: " << seglist2[0] << std::endl;
std::cout << "seglist2[1]: " << seglist2[1] << std::endl;
if(isNumbers(seglist2[1])){
    item->setAttribute(seglist2[0], atoi(seglist2[1].c_str()));
in every
Code:
                    if(std::isdigit(atoi((char*)seglist2[1].c_str())) || atoi((char*)seglist2[1].c_str()) >= 1){
                        item->setAttribute(seglist2[0], atoi((char*)seglist2[1].c_str()));
                    }else{
                        item->setAttribute(seglist2[0], seglist2[1]);
                    }
can u modify of pastebin?
 
Use following instead:

C++:
if(seglist2.size() != 2){
    std::cout << "Error: seglist2 contains improper amount of segments (" << test2 << ")." << std::endl;
    continue;
}
else if(isNumbers(seglist2[1])){
    item->setAttribute(seglist2[0], atoi(seglist2[1].c_str()));
}
else {
    item->setAttribute(seglist2[0], seglist2[1]);
}
 
Use following instead:

C++:
if(seglist2.size() != 2){
    std::cout << "Error: seglist2 contains improper amount of segments (" << test2 << ")." << std::endl;
    continue;
}
else if(isNumbers(seglist2[1])){
    item->setAttribute(seglist2[0], atoi(seglist2[1].c_str()));
}
else {
    item->setAttribute(seglist2[0], seglist2[1]);
}
Lua:
Thread 2 "theforgottenser" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff2642700 (LWP 2886)]
0x00007ffff5820464 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt full
#0  0x00007ffff5820464 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#1  0x00000000005b425e in atoi (__nptr=<optimized out>) at /usr/include/stdlib.h:280
No locals.
#2  ProtocolGame::sendMarketBrowseOwnOffers (this=<optimized out>, buyOffers=..., sellOffers=...) at protocolgame.cpp:3641
        test2 = <incomplete type>
        segment2 = "mo"
        seglist2 = std::vector of length 1, capacity 1 = {"mo"}
        i = 16
        itt = <optimized out>
        test = <incomplete type>
        segment = "mo"
        seglist = std::vector of length 17, capacity 32 = {"poke#Mewtwo", "poke#Mewtwo", "ball#poke", "ball#poke", "reverseIcon#poke", "reverseIcon#poke",
          "happy#255", "hp#0", "blink#cd:1610383732", "blink#cd:1610383732", "move1#cd:1610383733", "move1#cd:1610383733", "move2#cd:1610383733",
          "move2#cd:1610383733", "move3#cd:1610383733", "move3#cd:1610383733", "mo"}
        item = <optimized out>
        it = <optimized out>
        end = <optimized out>
        msg = {px = 0x7fffec255a40, pn = {pi_ = <optimized out>}}
#3  0x000000000047cc5e in Player::sendMarketBrowseOwnOffers (sellOffers=..., buyOffers=..., this=0x7fffa99ac1a0) at player.h:669
No locals.
#4  Game::playerBrowseMarketOwnOffers (this=0x8c0c40 <g_game>, playerId=<optimized out>) at game.cpp:6451
        player = 0x7fffa99ac1a0
        buyOffers = @0x7ffff26419e0: {<std::__cxx11::_List_base<MarketOffer, std::allocator<MarketOffer> >> = {
            _M_impl = {<std::allocator<std::_List_node<MarketOffer> >> = {<__gnu_cxx::new_allocator<std::_List_node<MarketOffer> >> = {<No data fields>}, <No data fields>}, _M_node = {<std::__detail::_List_node_base> = {_M_next = 0x7ffff26419e0, _M_prev = 0x7ffff26419e0}, _M_data = 0}}}, <No data fields>}
        sellOffers = @0x7ffff2641a00: {<std::__cxx11::_List_base<MarketOffer, std::allocator<MarketOffer> >> = {
            _M_impl = {<std::allocator<std::_List_node<MarketOffer> >> = {<__gnu_cxx::new_allocator<std::_List_node<MarketOffer> >> = {<No data fields>}, <No data fields>}, _M_node = {<std::__detail::_List_node_base> = {_M_next = 0x7fffa9625ea0, _M_prev = 0x7fffa94a6eb0}, _M_data = 8}}}, <No data fields>}
#5  0x00000000005c2d4d in boost::_mfi::mf1<bool, Game, unsigned int>::operator() (a1=<optimized out>, p=<optimized out>, this=<optimized out>)
    at /usr/include/boost/bind/mem_fn_template.hpp:165
No locals.
#6  boost::_bi::list2<boost::_bi::value<Game*>, boost::_bi::value<unsigned int> >::operator()<bool, boost::_mfi::mf1<bool, Game, unsigned int>, boost::_bi::list0> (a=<synthetic pointer>, f=..., this=<optimized out>) at /usr/include/boost/bind/bind.hpp:303
No locals.
#7  boost::_bi::bind_t<bool, boost::_mfi::mf1<bool, Game, unsigned int>, boost::_bi::list2<boost::_bi::value<Game*>, boost::_bi::value<unsigned int> > >::operator() (this=<optimized out>) at /usr/include/boost/bind/bind_template.hpp:20
No locals.
#8  boost::detail::function::void_function_obj_invoker0<boost::_bi::bind_t<bool, boost::_mfi::mf1<bool, Game, unsigned int>, boost::_bi::list2<boost::_bi::value<Game*>, boost::_bi::value<unsigned int> > >, void>::invoke (function_obj_ptr=...) at /usr/include/boost/function/function_template.hpp:159
---Type <return> to continue, or q <return> to quit---

Line 6451 onGame.cpp: player->sendMarketBrowseOwnOffers(buyOffers, sellOffers);
 
Seems like you didn't change all occurences. here's the one from error (3641).
#2 ProtocolGame::sendMarketBrowseOwnOffers (this=<optimized out>, buyOffers=..., sellOffers=...) at protocolgame.cpp:3641

1610671429669.png


I did update the rest occurrences of above code, try this:

Consider creating separate functions for these repeated parts of the code.
 
Seems like you didn't change all occurences. here's the one from error (3641).
#2 ProtocolGame::sendMarketBrowseOwnOffers (this=<optimized out>, buyOffers=..., sellOffers=...) at protocolgame.cpp:3641

View attachment 53730


I did update the rest occurrences of above code, try this:

Consider creating separate functions for these repeated parts of the code.
Give this error and cant add item on market, but stop crashes.

Code:
Error: seglist2 contains improper amount of segments (0).
Error: seglist2 contains improper amount of segments (0).
Error: seglist2 contains improper amount of segments (0).
Error: seglist2 contains improper amount of segments (0).
Error: seglist2 contains improper amount of segments (0).
Error: seglist2 contains improper amount of segments (0).
 
Back
Top