Leon Bottou wrote: > On Monday 29 December 2008 18:39:17 Thomas Viehmann wrote: >> Hi, >> So here is something even better (IMHO): Change map_lookup to return the >> return value (note that this would be funny if we stored NULLs in the > > Ok. I am doing that upstream. > This is the best way to avoid the pitfalls of the ANSI C strict aliasing > rules. > These stupid rules basically prevent us from accessing > an arbitrary pointer using a void* type. > I wonder why they did not handle the case of void* pointers > in the rules. I did not find any explanation online...
The curse of post-midnight sending patches had me attach a broken version, though, because I had only updated the binaries after the initial compile. Sorry about all the ill attempts, here is the hopefully final thing. Kind regards T. -- Thomas Viehmann, http://thomas.viehmann.net/
--- djvulibre-3.5.20/debian/changelog +++ djvulibre-3.5.20/debian/changelog @@ -1,3 +1,13 @@ +djvulibre (3.5.20-8+lenny1) testing; urgency=low + + * Non-maintainer upload. + * gui/nsdejavu/nsdejavu.c: Don't assume NPP_SetWindow is + alsways passed good data. Patch from upstream. + Make map_lookup return the result instead of an error code. + Closes: #504340 + + -- Thomas Viehmann <t...@beamnet.de> Tue, 30 Dec 2008 00:11:49 +0100 + djvulibre (3.5.20-8+lenny0) testing; urgency=low * Non-maintainer upload to testing. --- djvulibre-3.5.20.orig/gui/nsdejavu/nsdejavu.c +++ djvulibre-3.5.20/gui/nsdejavu/nsdejavu.c @@ -815,8 +815,8 @@ m->nbuckets = new_nbuckets; } -static int -map_lookup(Map *m, void *key, void *pval) +static void* +map_lookup(Map *m, void *key) { int h; struct map_entry_s *q; @@ -824,12 +824,10 @@ h = hash(key, m->nbuckets); for (q=m->buckets[h]; q; q=q->next) if (q->key == key) { - if (pval) - *(void**)pval = q->val; - return 1; + return q->val; } } - return -1; + return NULL; } static int @@ -1167,12 +1165,12 @@ switch(reqp->req_num) { case CMD_SHOW_STATUS: - if (map_lookup(&instance, reqp->id, &inst) >= 0) + if ((inst = map_lookup(&instance, reqp->id))) if (inst->widget) NPN_Status(inst->np_instance, reqp->status); break; case CMD_GET_URL: - if (map_lookup(&instance, reqp->id, &inst) >= 0) + if ((inst = map_lookup(&instance, reqp->id))) { const char *target = (reqp->target && reqp->target[0]) ? reqp->target : 0; @@ -1180,7 +1178,7 @@ } break; case CMD_GET_URL_NOTIFY: - if (map_lookup(&instance, reqp->id, &inst) >= 0) + if ((inst = map_lookup(&instance, reqp->id))) { const char *target = (reqp->target && reqp->target[0]) ? reqp->target : 0; @@ -1297,7 +1295,7 @@ { Instance *inst; void *id = (void*)cl_data; - if (map_lookup(&instance, id, &inst) >= 0) + if ((inst = map_lookup(&instance, id))) if (Resize(id) <= 0) ProgramDied(); } @@ -1325,7 +1323,7 @@ Instance *inst; void *id = (void*)cl_data; *cont = True; - if (map_lookup(&instance, id, &inst) >= 0) + if ((inst = map_lookup(&instance, id))) { Widget wid = inst->widget; Display *dpy = XtDisplay(wid); @@ -1567,7 +1565,7 @@ resizeCallback here and send the appropriate request to the application */ Instance *inst; - if (map_lookup(&instance, id, &inst) < 0) + if (! (inst = map_lookup(&instance, id))) return 1; if (inst->widget) { @@ -1591,7 +1589,7 @@ Detach(void * id) { Instance *inst; - if (map_lookup(&instance, id, &inst) < 0) + if (! (inst = map_lookup(&instance, id))) return 1; if (inst->widget) { @@ -1630,7 +1628,7 @@ XColor cell; XSync(displ, False); - if (map_lookup(&instance, id, &inst) < 0) + if (! (inst = map_lookup(&instance, id))) return 1; widget = XtWindowToWidget(displ, window); @@ -1968,7 +1966,7 @@ goto problem; if (ReadPointer(pipe_read, &id, 0, 0) <= 0) goto problem; - if (map_lookup(&instance, id, &inst) >= 0) + if ((inst = map_lookup(&instance, id))) /* This can happen because we do not clear the instance array when restarting djview. We just undo it... */ @@ -1988,7 +1986,7 @@ void * id = np_inst->pdata; SavedData saved_data; - if (map_lookup(&instance, id, &inst) < 0) + if (! (inst = map_lookup(&instance, id))) return NPERR_INVALID_INSTANCE_ERROR; /* Detach the main window, if not already detached */ NPP_SetWindow(np_inst, 0); @@ -2035,7 +2033,7 @@ void * id = np_inst->pdata; Window cur_window, new_window; - if (map_lookup(&instance, id, &inst) < 0) + if (! (inst = map_lookup(&instance, id))) return NPERR_INVALID_INSTANCE_ERROR; cur_window = inst->window; new_window = (win_str) ? (Window) win_str->window : 0; @@ -2054,9 +2052,9 @@ } if (new_window) { - NPSetWindowCallbackStruct *cbs - = (NPSetWindowCallbackStruct *) win_str->ws_info; - Display * displ=cbs->display; + Display *displ = 0; + if (NPN_GetValue(np_inst, NPNVxDisplay, &displ) != NPERR_NO_ERROR) + displ = ((NPSetWindowCallbackStruct *)(win_str->ws_info))->display; if (!IsConnectionOK(FALSE)) return NPERR_GENERIC_ERROR; if (Attach(displ, new_window, id) < 0) @@ -2075,7 +2073,7 @@ Instance *inst = 0; void * id = np_inst->pdata; - if (map_lookup(&instance, id, &inst) > 0) + if ((inst = map_lookup(&instance, id))) if (inst->widget) { if (printInfo && printInfo->mode==NP_FULL) @@ -2103,7 +2101,7 @@ void * id = np_inst->pdata; void * sid = 0; - if (map_lookup(&instance, id, &inst) < 0) + if (! (inst = map_lookup(&instance, id))) return NPERR_INVALID_INSTANCE_ERROR; if ( (WriteInteger(pipe_write, CMD_NEW_STREAM) <= 0) || @@ -2136,7 +2134,7 @@ if (sid) { - if (map_lookup(&strinstance, sid, 0) < 0) + if (! map_lookup(&strinstance, sid)) return res; if ( (WriteInteger(pipe_write, CMD_WRITE) <= 0) || (WritePointer(pipe_write, sid) <= 0) || @@ -2164,7 +2162,7 @@ NPP_DestroyStream(NPP np_inst, NPStream *stream, NPError reason) { void * sid = stream->pdata; - if (map_lookup(&strinstance, sid, 0) < 0) + if (! map_lookup(&strinstance, sid)) return NPERR_INVALID_INSTANCE_ERROR; if (!IsConnectionOK(FALSE)) return NPERR_GENERIC_ERROR;