EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Server Code Submissions (https://www.eqemulator.org/forums/forumdisplay.php?f=669)
-   -   Small fix for Database::StoreCharacter for MSVC (https://www.eqemulator.org/forums/showthread.php?t=25148)

BatCountry 04-30-2008 07:01 PM

Small fix for Database::StoreCharacter for MSVC
 
VS.NET Professional 2005 builds of eqemu seem to barf when provided a very large color number for an item (namely the default value) as it's above the signed max value. As the number is stored as a uint32, that shouldn't be a problem, but the StoreCharacter command uses a format string with %d as the value for the number.

On at least my install of VS.NET 2k5, this causes the number to be automatically cast to a signed int, converting it to a bad value, which MySQL complains (in strict mode) is out of range.

A simple fix is replacing the values which might be very large with %0u rather than %d fixes this without complaint in STRICT mode.

Also of note is that the query string is deleted before the debug message about the query string, resulting in a debug message which says that query "<NULL>" is invalid.

Original code at line database.cpp 557-571
Code:

                        MakeAnyLenString
                        (
                                &invquery,
                                "INSERT INTO inventory SET "
                                "charid=%d, slotid=%d, itemid=%d, charges=%d, color=%d",
                                charid, i, newinv->GetItem()->ID,
                                newinv->GetCharges(), newinv->GetColor()
                        );

                        RunQuery(invquery, strlen(invquery), errbuf, 0, &affected_rows);
                        safe_delete_array(invquery);
                        if(!affected_rows)
                        {
                                LogFile->write(EQEMuLog::Error, "StoreCharacter inventory failed.  Query '%s' %s", invquery, errbuf);
                        }

Simple fix:
Code:

                        MakeAnyLenString
                        (
                                &invquery,
                                "INSERT INTO inventory SET "
                                "charid=%0u, slotid=%0d, itemid=%0u, charges=%0d, color=%0u",
                                charid, i, newinv->GetItem()->ID,
                                newinv->GetCharges(), newinv->GetColor()
                        );

                        RunQuery(invquery, strlen(invquery), errbuf, 0, &affected_rows);
                        if(!affected_rows)
                        {
                                LogFile->write(EQEMuLog::Error, "StoreCharacter inventory failed.  Query '%s' %s", invquery, errbuf);
                        }
                        safe_delete_array(invquery);

Not a super large priority, but it does fix a potential problem with Windows builds, as well as a small debug bug. :)


All times are GMT -4. The time now is 09:31 PM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.