summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHakan Kvist <fribid@svenskascenarbetaremotkonfetti.se>2010-02-19 22:14:48 +0100
committerSamuel Lidén Borell <samuel@slbdata.se>2010-02-20 00:03:36 +0100
commit044097f7d6857b8bc91e216ab8a3503a93c89e1d (patch)
tree8e8912a32f31e2849747a077d619c93c60ca25ae
parentc8464cc1b50d353eb3ab5d5a21fee41957372748 (diff)
downloadfribid-044097f7d6857b8bc91e216ab8a3503a93c89e1d.tar.gz
fribid-044097f7d6857b8bc91e216ab8a3503a93c89e1d.tar.bz2
fribid-044097f7d6857b8bc91e216ab8a3503a93c89e1d.zip
Fixed crash on 64 bit platforms.
The npn_getvalue on NPNVnetscapeWindow returns a Window on X11. A X11 Window is defined as an unsigned long. This happends to be 8 bytes on amd64 and 4 bytes on i386 (int is 4 bytes on both amd64 and i386). So prevously the code worked on i386, but not on amd64 where you instead got a SIGSEV. Signed-off-by: Hakan Kvist <fribid@svenskascenarbetaremotkonfetti.se>
-rw-r--r--plugin/npobject.c23
-rw-r--r--plugin/plugin.c3
-rw-r--r--plugin/plugin.h6
3 files changed, 22 insertions, 10 deletions
diff --git a/plugin/npobject.c b/plugin/npobject.c
index 4322013..d25706a 100644
--- a/plugin/npobject.c
+++ b/plugin/npobject.c
@@ -36,6 +36,8 @@
#include <npapi.h>
#include <npruntime.h>
+#include <X11/X.h>
+
#include "npobject.h"
@@ -76,6 +78,7 @@ static char *getWindowProperty(NPP instance, const char *const identifiers[]) {
if (!obj) return NULL;
const char *const *identifier = &identifiers[0];
+
while (1) {
NPVariant value;
@@ -154,12 +157,14 @@ static char *getDocumentIP(NPP instance) {
/**
* Returns the native ID of the browser window, or -1 on error.
*/
-static int getWindowId(NPP instance) {
- int id;
- if (NPN_GetValue(instance, NPNVnetscapeWindow, &id) == NPERR_NO_ERROR) {
- return id;
+static bool getWindowId(NPP instance, Window *id) {
+ if (id == NULL) {
+ return false;
+ }
+ if (NPN_GetValue(instance, NPNVnetscapeWindow, id) == NPERR_NO_ERROR) {
+ return true;
} else {
- return -1;
+ return false;
}
}
@@ -330,14 +335,18 @@ static NPClass baseClass = {
/* Object construction */
static NPObject *npobject_new(NPP instance, PluginType pluginType) {
- PluginObject *obj = (PluginObject*)NPN_CreateObject(instance, &baseClass);
+ PluginObject *obj;
+ Window windowId;
+
+ obj = (PluginObject*)NPN_CreateObject(instance, &baseClass);
if (!obj) return NULL;
assert(obj->base._class != NULL);
char *url = getDocumentURL(instance);
char *hostname = getDocumentHostname(instance);
char *ip = getDocumentIP(instance);
- int windowId = getWindowId(instance);
+ getWindowId(instance, &windowId);
+
obj->plugin = plugin_new(pluginType,
(url != NULL ? url : ""),
(hostname != NULL ? hostname : ""),
diff --git a/plugin/plugin.c b/plugin/plugin.c
index 4fd3d97..c8d8930 100644
--- a/plugin/plugin.c
+++ b/plugin/plugin.c
@@ -36,8 +36,9 @@ static const char *activeURLs[MAX_WINDOWS];
Plugin *plugin_new(PluginType pluginType, const char *url,
const char *hostname, const char *ip,
- int windowId) {
+ Window windowId) {
Plugin *plugin = calloc(1, sizeof(Plugin));
+
if (!plugin) return NULL;
plugin->type = pluginType;
plugin->url = strdup(url);
diff --git a/plugin/plugin.h b/plugin/plugin.h
index 3fd1d9e..05ccd38 100644
--- a/plugin/plugin.h
+++ b/plugin/plugin.h
@@ -25,6 +25,8 @@
#ifndef __PLUGIN_H__
#define __PLUGIN_H__
+#include <X11/X.h>
+
typedef enum {
PT_Version,
PT_Authentication,
@@ -42,7 +44,7 @@ typedef struct {
char *url;
char *hostname;
char *ip;
- int windowId;
+ Window windowId;
PluginError lastError;
union {
@@ -70,7 +72,7 @@ typedef struct {
/* Plugin creation */
Plugin *plugin_new(PluginType pluginType, const char *url,
const char *hostname, const char *ip,
- int windowId);
+ Window windowId);
void plugin_free(Plugin *plugin);
/* Javascript API */