[C++]FIX Cube_request_result_list: Too long cube result list text

12/15/2015 15:23 Exygo#1
How to fix Cube_request_result_list: Too long cube result list text. ?


1. Go in cube.cpp

2. Replace:
Code:
        if (resultText.size() - 20 >= CHAT_MAX_LEN)
        {
            sys_err("[CubeInfo] Too long cube result list text. (NPC: %d, length: %d)", npcVNUM, resultText.size());
            resultText.clear();
            resultCount = 0;
        }
With this:

The problem was caused by a comparison between a negative number and a number
12/15/2015 16:34 .Shōgun#2
Sorry, it's not this one xD never mind
12/15/2015 22:25 Isolation_#3
Hier noch eine Version:
Code:
        int resultsize = (resultText.size() < 20) ? (20 - resultText.size()) : (resultText.size() - 20);
        if (resultsize >= CHAT_MAX_LEN)
        {
            sys_err("[CubeInfo] Too long cube result list text. (NPC: %d, resultsize: %d, length: %d)", npcVNUM, resultsize, resultText.size());
            resultText.clear();
            resultCount = 0;
        }
So ganz ohne Werbung und etwas kürzer. Eigentlich kann man sich sogar die Variable schenken.
12/15/2015 23:06 rollback#4
Quote:
Originally Posted by Isolation_ View Post
Hier noch eine Version:
Code:
        int resultsize = (resultText.size() < 20) ? (20 - resultText.size()) : (resultText.size() - 20);
        if (resultsize >= CHAT_MAX_LEN)
        {
            sys_err("[CubeInfo] Too long cube result list text. (NPC: %d, resultsize: %d, length: %d)", npcVNUM, resultsize, resultText.size());
            resultText.clear();
            resultCount = 0;
        }
So ganz ohne Werbung und etwas kürzer. Eigentlich kann man sich sogar die Variable schenken.
Und kürzer ist besser?
Finde die Lesbarkeit sehr wichtig.
Deine Lösung finde ich besser zu lesen als die des erstellers, das ganze allerdings direkt im if block zu schreiben wäre meiner Meinung nach allerdings zu unübersichtlich.
12/15/2015 23:24 fcsk_aim#5
This fix it's useless.
I never had this in my syserr. :d
12/15/2015 23:43 rollback#6
Quote:
Originally Posted by fcsk_aim View Post
This fix it's useless.
I never had this in my syserr. :d
My gf never got pregnant yet, why should i prevent?
12/16/2015 00:11 fcsk_aim#7
Quote:
Originally Posted by Seחsi View Post
My gf never got pregnant yet, why should i prevent?
There's nothing to prevent.
12/16/2015 00:23 JeyMaker#8
Quote:
Originally Posted by .Shōgun View Post
Sorry, it's not this one xD never mind
Sorry it's not this one -> xD <- Yes I think u r a bit mad today?
12/16/2015 14:46 Lefloyd#9
Warum kam eigentlich keiner auf die Idee einfach eine int-Konvertierung zu benutzen? o_o
12/16/2015 23:42 Mashkin#10
Quote:
Originally Posted by Lefloyd View Post
Warum kam eigentlich keiner auf die Idee einfach eine int-Konvertierung zu benutzen? o_o
And why not just do this - which will only fail if CHAT_MAX_LEN > MAX_INT - 20.
This is basic math.
Code:
if (resultText.size() >= CHAT_MAX_LEN + 20)
This inequation also shows that the original code is pretty much bullshit because the resultText is asserted to be 20 characters longer than CHAT_MAX_LEN.
In fact, resultText should be at maximum 20 characters shorter than CHAT_MAX_LEN.

The number 20 comes from the string to which resultText is appended which is assumed 14 + 6 = 20 characters in length.
In the code, the inserted numbers are assumed to be at maximum 5 and 1 characters long.
This might not be true for NPCs with vnums greater than 99.999 or(vnums ares of type WORD) more than 9 results.

Deducing 20 from CHAT_MAX_LEN thus does not safely determine the maximum length for resultText in some quite realistic cases, especially as resultCount and with it (on average proportionally) resultText's length grow.
Code:
ch->ChatPacket(CHAT_TYPE_COMMAND, "cube r_list %d %d %s", npcVNUM, resultCount, resultText.c_str());
// example: "cube r_list 20383 4 ..."
As becomes clear the function is actually broken in several ways, and your proposed change only removes one minor issue of it.

Your turn to fix this.
12/17/2015 21:16 DasSchwarzeT#11
Quote:
Originally Posted by Seחsi View Post
My gf never got pregnant yet, why should i prevent?
[Only registered and activated users can see links. Click Here To Register...]
Don't even expect her to get pregnant.