Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8312631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:13:50+00:00 2026-06-08T20:13:50+00:00

When I was testing my application, it crashed. And after debugging it took me

  • 0

When I was testing my application, it crashed. And after debugging it took me to this piece of code:

static cell AMX_NATIVE_CALL n_fblockwrite(AMX *amx, cell *params)
{
    cell *cptr;
    cell count;

    amx_GetAddr(amx,params[2],&cptr);

    if (cptr!=NULL)
    {
        cell max=params[3];
        ucell v;

        for (count=0; count<max; count++)
        {
            v=(ucell)*cptr++;
            if (StorageWriteFile((SolFSHandle)params[1],amx_Align32(&v),max*sizeof(cell),&g_amount_read)!=1)
            {
                break;/* write error */
            }
        }/* for */
    }/* if */
    return count;
}

and it seems to crash at:

            if (StorageWriteFile((SolFSHandle)params[1],amx_Align32(&v),max*sizeof(cell),&g_amount_read)!=1)

exactly at the second parameter:

amx_Align32(&v),

with a 0x0 0x5 0x0 access voilation exception

The code of the amx_Align32 stuff is external so I don’t have access to the source of it, but in my source it looks like this:

#define NUDE _declspec(naked) 

NUDE uint32_t * AMXAPI amx_Align32(uint32_t *v)
{
    _asm mov eax, pAMXFunctions;
    _asm jmp dword ptr [eax+PLUGIN_AMX_EXPORT_Align32*4];
}

with this as the export stuff:

enum PLUGIN_AMX_EXPORT
{
    PLUGIN_AMX_EXPORT_Align16       = 0,
    PLUGIN_AMX_EXPORT_Align32       = 1,
    PLUGIN_AMX_EXPORT_Align64       = 2,
    PLUGIN_AMX_EXPORT_Allot         = 3,
    PLUGIN_AMX_EXPORT_Callback      = 4,
    PLUGIN_AMX_EXPORT_Cleanup       = 5,
    PLUGIN_AMX_EXPORT_Clone         = 6,
    PLUGIN_AMX_EXPORT_Exec          = 7,
    PLUGIN_AMX_EXPORT_FindNative    = 8,
    PLUGIN_AMX_EXPORT_FindPublic    = 9,
    PLUGIN_AMX_EXPORT_FindPubVar    = 10,
    PLUGIN_AMX_EXPORT_FindTagId     = 11,
    PLUGIN_AMX_EXPORT_Flags         = 12,
    PLUGIN_AMX_EXPORT_GetAddr       = 13,
    PLUGIN_AMX_EXPORT_GetNative     = 14,
    PLUGIN_AMX_EXPORT_GetPublic     = 15,
    PLUGIN_AMX_EXPORT_GetPubVar     = 16,
    PLUGIN_AMX_EXPORT_GetString     = 17,
    PLUGIN_AMX_EXPORT_GetTag        = 18,
    PLUGIN_AMX_EXPORT_GetUserData   = 19,
    PLUGIN_AMX_EXPORT_Init          = 20,
    PLUGIN_AMX_EXPORT_InitJIT       = 21,
    PLUGIN_AMX_EXPORT_MemInfo       = 22,
    PLUGIN_AMX_EXPORT_NameLength    = 23,
    PLUGIN_AMX_EXPORT_NativeInfo    = 24,
    PLUGIN_AMX_EXPORT_NumNatives    = 25,
    PLUGIN_AMX_EXPORT_NumPublics    = 26,
    PLUGIN_AMX_EXPORT_NumPubVars    = 27,
    PLUGIN_AMX_EXPORT_NumTags       = 28,
    PLUGIN_AMX_EXPORT_Push          = 29,
    PLUGIN_AMX_EXPORT_PushArray     = 30,
    PLUGIN_AMX_EXPORT_PushString    = 31,
    PLUGIN_AMX_EXPORT_RaiseError    = 32,
    PLUGIN_AMX_EXPORT_Register      = 33,
    PLUGIN_AMX_EXPORT_Release       = 34,
    PLUGIN_AMX_EXPORT_SetCallback   = 35,
    PLUGIN_AMX_EXPORT_SetDebugHook  = 36,
    PLUGIN_AMX_EXPORT_SetString     = 37,
    PLUGIN_AMX_EXPORT_SetUserData   = 38,
    PLUGIN_AMX_EXPORT_StrLen        = 39,
    PLUGIN_AMX_EXPORT_UTF8Check     = 40,
    PLUGIN_AMX_EXPORT_UTF8Get       = 41,
    PLUGIN_AMX_EXPORT_UTF8Len       = 42,
    PLUGIN_AMX_EXPORT_UTF8Put       = 43,
};

So, how can I align the data in the cell?
Or maybe I don’t need to align the data?
The original code was this:

  if (fwrite(aligncell(&v),sizeof(cell),1,(FILE*)params[1])!=1)

I’m converting it to use with SolFS.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:13:52+00:00Added an answer on June 8, 2026 at 8:13 pm

    My guess would be that the temporary cell you create is not aligned, and you’re going off the end of it when you call amx_Align32:

    ucell v;   // Not aligned to 32-bit boundary
    

    So that error probably happens when you try to read it (during StorageWriteFile). But the other problem here is that you have already written the data to potentially non-aligned memory. You need to align your memory before you write data to it.

    Without relying on compiler alignment pragmas etc, what you can do is this:

    char buffer[sizeof(ucell)+4];
    ucell *pv = (ucell*) (buffer + 4 - (buffer % 4));  // Align to 32-bit
    

    Now you have an aligned pointer to a ucell and you shouldn’t need to call amx_Align32. Instead of the pointer arithmetic, you could probably substitute a call to amx_Align32:

    char buffer[sizeof(ucell)+4];
    ucell *pv = (ucell*) amxAlign32( (uint32_t*)buffer );
    

    Now you can put the data in as usual (I assume the type ucell is compatible with the cell types you’re putting in it):

    *(cell*)pv = *cptr++;
    

    Oh, and now that I got all the way to here, I notice that your call to StorageWriteFile is wrong. Look at how many bytes you’re writing each time around the loop: max*sizeof(cell) – that surely can’t be what you intended.

    Regardless of that paragraph above, everything I’ve said is still relevant. If you want to use memory alignment correctly, you need to obtain the aligned pointer first and then write the data in the correct location. Also, watch out for running off the end of your buffers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to begin unit testing our application, because I believe that this is
After executing some new code, my C++ application started to behave strange (incorrect or
I have a map application in Android and am testing this app on Android
I have written a psychological testing application, in which the user is presented with
Currently I'm using TestNG framework for testing application business logic, i added some Servlet
Is there any way to update my beta testing application on windows phone marketplace?
I am testing an application using Selenium IDE. There is a table with unstable
I am unit testing an application on the iPhone, and I'm trying to develop
I am testing an application and need to test it with different screen resolutions
I'm testing my application as grails run-app. I have read How to remove app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.