diff --git a/mozilla/toolkit/components/remote/nsGTKRemoteService.cpp b/mozilla/toolkit/components/remote/nsGTKRemoteService.cpp index 5743ac87518..0c405d32f1e 100644 --- a/mozilla/toolkit/components/remote/nsGTKRemoteService.cpp +++ b/mozilla/toolkit/components/remote/nsGTKRemoteService.cpp @@ -81,6 +81,14 @@ #define MOZILLA_PROGRAM_PROP "_MOZILLA_PROGRAM" #define MOZILLA_COMMANDLINE_PROP "_MOZILLA_COMMANDLINE" +#ifdef IS_BIG_ENDIAN +#define TO_LITTLE_ENDIAN32(x) \ + ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) +#else +#define TO_LITTLE_ENDIAN32(x) (x) +#endif + #ifdef MOZ_XUL_APP const unsigned char kRemoteVersion[] = "5.1"; #else @@ -340,7 +348,7 @@ nsGTKRemoteService::HandleCommandLine(char* aBuffer, nsIDOMWindow* aWindow) // [argc][offsetargv0][offsetargv1...]\0\0argv[1]...\0 // (offset is from the beginning of the buffer) - PRInt32 argc = *NS_REINTERPRET_CAST(PRInt32*, aBuffer); + PRInt32 argc = TO_LITTLE_ENDIAN32(*NS_REINTERPRET_CAST(PRInt32*, aBuffer)); char *wd = aBuffer + ((argc + 1) * sizeof(PRInt32)); #ifdef DEBUG_bsmedberg @@ -362,7 +370,7 @@ nsGTKRemoteService::HandleCommandLine(char* aBuffer, nsIDOMWindow* aWindow) PRInt32 *offset = NS_REINTERPRET_CAST(PRInt32*, aBuffer) + 1; for (int i = 0; i < argc; ++i) { - argv[i] = aBuffer + offset[i]; + argv[i] = aBuffer + TO_LITTLE_ENDIAN32(offset[i]); #ifdef DEBUG_bsmedberg printf(" argv[%i]:\t%s\n", i, argv[i]); @@ -474,7 +482,7 @@ nsGTKRemoteService::HandlePropertyChange(GtkWidget *aWidget, return FALSE; // Failed to get the data off the window or it was the wrong type? - if (!data || !*data) + if (!data || !TO_LITTLE_ENDIAN32(*NS_REINTERPRET_CAST(PRInt32*, data))) return FALSE; // cool, we got the property data. @@ -519,7 +527,7 @@ nsGTKRemoteService::HandlePropertyChange(GtkWidget *aWidget, return FALSE; // Failed to get the data off the window or it was the wrong type? - if (!data || !*data) + if (!data || !TO_LITTLE_ENDIAN32(*NS_REINTERPRET_CAST(PRInt32*, data))) return FALSE; // cool, we got the property data. diff --git a/mozilla/widget/src/xremoteclient/XRemoteClient.cpp b/mozilla/widget/src/xremoteclient/XRemoteClient.cpp index 5fa8ae55ec6..9334fe09e12 100644 --- a/mozilla/widget/src/xremoteclient/XRemoteClient.cpp +++ b/mozilla/widget/src/xremoteclient/XRemoteClient.cpp @@ -67,6 +67,14 @@ #define MOZILLA_PROFILE_PROP "_MOZILLA_PROFILE" #define MOZILLA_PROGRAM_PROP "_MOZILLA_PROGRAM" +#ifdef IS_BIG_ENDIAN +#define TO_LITTLE_ENDIAN32(x) \ + ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) +#else +#define TO_LITTLE_ENDIAN32(x) (x) +#endif + #ifndef MAX_PATH #define MAX_PATH 1024 #endif @@ -691,19 +699,19 @@ XRemoteClient::DoSendCommandLine(Window aWindow, PRInt32 argc, char **argv, if (!buffer) return NS_ERROR_OUT_OF_MEMORY; - buffer[0] = argc; + buffer[0] = TO_LITTLE_ENDIAN32(argc); char *bufend = (char*) (buffer + argc + 1); bufend = estrcpy(cwdbuf, bufend); for (int i = 0; i < argc; ++i) { - buffer[i + 1] = bufend - ((char*) buffer); + buffer[i + 1] = TO_LITTLE_ENDIAN32(bufend - ((char*) buffer)); bufend = estrcpy(argv[i], bufend); } #ifdef DEBUG_bsmedberg - PRInt32 debug_argc = *buffer; + PRInt32 debug_argc = TO_LITTLE_ENDIAN32(*buffer); char *debug_workingdir = (char*) (buffer + argc + 1); printf("Sending command line:\n" @@ -715,7 +723,7 @@ XRemoteClient::DoSendCommandLine(Window aWindow, PRInt32 argc, char **argv, PRInt32 *debug_offset = buffer + 1; for (int debug_i = 0; debug_i < debug_argc; ++debug_i) printf(" argv[%i]:\t%s\n", debug_i, - ((char*) buffer) + debug_offset[debug_i]); + ((char*) buffer) + TO_LITTLE_ENDIAN32(debug_offset[debug_i])); #endif XChangeProperty (mDisplay, aWindow, mMozCommandLineAtom, XA_STRING, 8,