[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

diffseq: Segfault if two vectors are entirely different

From: Philip Chimento
Subject: diffseq: Segfault if two vectors are entirely different
Date: Wed, 4 Feb 2015 22:59:32 -0800


I'm not sure if I'm using diffseq correctly here, but comparing two vectors of different lengths and no common elements seems to cause a segfault, as in the following toy example:

#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <stdbool.h>
#include "minmax.h"

#define ELEMENT char
#define EQUAL(a,b) (a == b)
#define OFFSET ssize_t
#define NOTE_INSERT(ctxt,xoff)
#define NOTE_DELETE(ctxt,yoff)
#define lint
#include "diffseq.h"

  char *expected = "abcd";
  char *actual = "efg";
  ssize_t expected_limit = 4;
  ssize_t actual_limit = 3;
  ssize_t *work_buffer;
  struct context ctxt;

  /* Allocate a work buffer */
  work_buffer = calloc(2 * (expected_limit + actual_limit + 3), sizeof(ssize_t));

  /* Call the Gnulib diff algorithm */
  ctxt.xvec = expected;
  ctxt.yvec = actual;
  ctxt.fdiag = work_buffer + actual_limit + 1;
  ctxt.bdiag = work_buffer + expected_limit + actual_limit + 3;
  ctxt.heuristic = 1;
  compareseq(0, expected_limit, 0, actual_limit, &ctxt);

  return 0;

This seems to be because diag() doesn't find a point of correspondence and therefore the comparison proceeds with garbage. Specifically, dmin is initialized to a negative value at the start of diag(). However, the comment at the top of diag() does say

> Compare in detail contiguous subsequences of the two vectors which are known, as a whole, to match each other.

and of course, I do know in this toy example that the vectors don't match each other as a whole. Am I trying to do something that diffseq isn't meant to do?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]