views:

69

answers:

2

I am making a patcher for a game but I get the error "initializer-string for array of array of chars is too long" from Mingw. I am trying to make a multidimensional array of chars to contain what functions to patch.
I have checked for other questions about this and found one where the asker forgot to add commas to the end of every string literal, but I have done that already.

Could anyone help me?

The source that triggers the error:

char patches2[][64] = {
    "CreateMutexW",
    "CreateRemoteThread",
    "CreateRemoteThreadEx",
    "?strcmp@unicode_string_trait@esl@@SAJPB_W0@Z",
    "??0?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@QAE@XZ",
    "??0?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@QAE@PB_W@Z",
    "??4?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@QAEAAV01@PB_W@Z",
    "?GetContent@?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@QBEPB_WXZ",
    "?SetLookUpOrder@CFileSystem@esl@@QAEXW4EFileLookUpOrder@esl_constant@2@@Z",
    "??1package_file_item@esl@@QAE@XZ",
    "??1CFormatter@esl@@QAE@XZ",
    "??6CFormatter@esl@@QAEAAV01@K@Z",
    "??6CFormatter@esl@@QAEAAV01@G@Z",
    "??6CFormatter@esl@@QAEAAV01@M@Z",
    "??6CFormatter@esl@@QAEAAV01@PB_W@Z",
    "??BCFormatter@esl@@QBE?AV?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@1@XZ",
    "?__time@etc@esl@@YAKXZ",
    "?ReadFSAA@CGameOptionMgr@pleione@@QAE?AW4EFSAA@pleione_constant@2@XZ",
    "?ReadFSAAQuality@CGameOptionMgr@pleione@@QAEKXZ",
    "?CleanUp@CPleione@pleione@@QAE_NXZ",
    "?SetSkyTime@CAtmosphere@pleione@@QAEXM@Z",
    "?SetCamera@CCameraControl@pleione@@QAEXPAVCScene@2@PAVITerrain@2@KFF@Z",
    "?GetObjectId@CObject@mint@@QBE_KXZ",
    "?ReadU8@CMessage@mint@@QAEEXZ",
    "?GetLuck@IParameter@core@@QAEMXZ",
    "?GetGateLocalName@CGateMgr@core@@QBE?BV?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@AB v34@@Z",
    "?GetLife@IParameterBase2@core@@QAEMXZ",
    "?GetLifeMax@IParameterBase2@core@@QAEMXZ",
    "?IsEiry@SItemEgoInfo@@QBE_NXZ",
    "?SetFog@CDungeonRegion@core@@QAEX_N@Z",
    "?GetTargetCombatPower@ICharacter@core@@QAE?AW4ECombatPower@@PBname2@@Z",
    "?GetCombatPower@IParameterBase2@core@@QBEMXZ",
    "?GetInterfaceDurability@IItem@core@@QBEKXZ",
    "?GetInterfaceDurabilityMax@IItem@core@@QBEKXZ",
    "?GetColor@IItem@core@@QBEKK@Z",
    "?IsElf@ICharacter@core@@QBE_NXZ",
    "?IsGiant@ICharacter@core@@QBE_NXZ",
    "?IsPet@ICharacter@core@@QBE_NXZ",
    "?IsNPC@ICharacter@core@@QBE_NXZ",
    "?IsNamedNPC@ICharacter@core@@QBE_NXZ",
    "?IsGoodNPC@ICharacter@core@@QBE_NXZ",
    "?Compile@CDefaultCompiler@pleione@@UAEPAVCCompiledText@2@ABV?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@ABUtext_option@2@@Z",
    "?Compile@CDefaultTagCompiler@pleione@@UAEPAVCCompiledText@2@ABV?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@ABUtext_option@2@@Z",
    "?Compile@CHTMLCompiler@pleione@@UAEPAVCCompiledText@2@ABV?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@ABUtext_option@2@@Z",
    "?_RenderGlowOverlay@CRendererContext@pleione@@AAEXXZ",
    "?GetExploLevel@IParameterBase2@core@@QBEGXZ",
    "?GetExploExpPercent@IParameter@core@@QBEMXZ",
    "?ParseCommand@CUserConsoleMgr@core@@QBE_NABV?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@AAVCUserConsole@2@@Z",
    "?Instance@CLocalizer@core@@SAAAname2@XZ",
    "?GetLocalText@CLocalizer@core@@QBE?AVCFormatter@esl@@ABV?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@4@@Z",
    "?stdapi_ShowChattingMessage@core@@YAX_KABV?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@1KKE@Z",
    "?stdapi_ShowCaption@core@@YAX_KABV?$CStringT@_WVunicode_string_trait@esl@@Vunicode_string_implement@2@@esl@@W4EMessageCaptionType@@KKK0@Z",
    "?stdapi_GetGlobalTime@core@@YA_KXZ",
    "?stdapi_GlobalTimeToGameTime@core@@YAX_KAAK11@Z",
    "?IsUsingNaosSupport@IServiceMgr@core@@QBE_NXZ",
    "?CheckFastStringID@IProp@core@@QBE_NPB_W@Z",
    "?IsUsableContents@IServiceMgr@core@@QBE_NW4EServiceContents@2@@Z",
    "?IsTransformed@ITransformMgr@core@@QBE_NXZ",
    "?GetFullSuitID@ICharacter@core@@QAEKXZ",
    "?IsBroken@IItem@core@@QBE_NXZ",
    "?CheckFastStringID@IItem@core@@QBE_NPB_W@Z",
    "?IsExpired@IItem@core@@QAE_N_K@Z",
    "?IsArenaField@IRegion@core@@QBE?B_NXZ",
    "?CanAttackTarget@IPVPMgr@core@@QBE_NPBVICharacter@2@@Z"
};
+2  A: 
char patches2[][64]

This is an array of arrays. The first dimension is determined automatically from the number of elements in the initializer. The second dimension is specified as being 64 chars.

Some of the string literals with which you initialize patches2 are longer than 64 characters in length. You need to increase the size to some value large enough to hold the largest C string in the initializer.

James McNellis
Ohhh... I got the two dimensions mixed up Xp
kotarou3
@kotarou3: then you probably really need an array of pointers to character strings: `char *patches[] = { ... };`.
Jonathan Leffler
+1  A: 

Well, the declaration for a single string looks like this:

const char* myString = "MyString";

What you probably want is an array of const char*s. You can change char patches2[][64] to const char* patches2[] (an array of pointers to const char).

The number of const char*s in patches2 can be calculated using sizeof():

const char* patches2[] = {"CreateMutexW", /* The rest... */ };
int numPatches = sizeof(patches2) / sizeof(const char*);

So if you add/remove some strings, you don't have to update the dimensions.

In silico
Your answer isn't really an answer to my question, but it's something I can put in :)
kotarou3