From peterli@salk.edu  Tue Jun 18 17:44:27 2013
Return-Path: <peterli@salk.edu>
X-Original-To: daved@localhost
Delivered-To: daved@localhost.windclimber.id.au
Received: from bandicoot.windclimber.id.au (localhost [127.0.0.1])
	by bandicoot.windclimber.id.au (Postfix) with ESMTP id 4AF4FA4F06
	for <daved@localhost>; Tue, 18 Jun 2013 17:44:27 +1000 (EST)
X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on
	ps12652.dreamhostps.com
X-Spam-Level: 
X-Spam-Status: No, score=-2.6 required=4.0 tests=BAYES_00 autolearn=ham
	version=3.2.5
X-Original-To: windclimber@ps12652.dreamhostps.com
Delivered-To: windclimber@ps12652.dreamhostps.com
Received: from www.gageconf.org.au
	by bandicoot.windclimber.id.au with IMAP (fetchmail-6.3.23)
	for <daved@localhost> (single-drop); Tue, 18 Jun 2013 17:44:27 +1000 (EST)
Received: from homiemail-mx4.g.dreamhost.com (caiajhbdccac.dreamhost.com [208.97.132.202])
	by ps12652.dreamhostps.com (Postfix) with ESMTP id E61FF17A3578
	for <windclimber@ps12652.dreamhostps.com>; Tue, 18 Jun 2013 17:43:46 +1000 (EST)
Received: from doublehelix.salk.edu (doublehelix.salk.edu [198.202.68.21])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by homiemail-mx4.g.dreamhost.com (Postfix) with ESMTPS id 26C5E768073
	for <daved@windclimber.id.au>; Tue, 18 Jun 2013 00:43:52 -0700 (PDT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by doublehelix.salk.edu (Postfix) with ESMTP id 926BAD99B7C
	for <daved@windclimber.id.au>; Tue, 18 Jun 2013 00:43:51 -0700 (PDT)
X-Virus-Scanned: amavisd-new at salk.edu
Received: from doublehelix.salk.edu ([127.0.0.1])
	by localhost (doublehelix.salk.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 1BQRZHTPNTTa for <daved@windclimber.id.au>;
	Tue, 18 Jun 2013 00:43:51 -0700 (PDT)
Received: from [192.168.0.107] (c-24-130-112-242.hsd1.ca.comcast.net [24.130.112.242])
	by doublehelix.salk.edu (Postfix) with ESMTP id 315F8D99B79
	for <daved@windclimber.id.au>; Tue, 18 Jun 2013 00:43:51 -0700 (PDT)
Message-ID: <51C00FB6.5030401@salk.edu>
Date: Tue, 18 Jun 2013 00:43:50 -0700
From: "Peter H. Li" <peterli@salk.edu>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130514 Thunderbird/17.0.6
MIME-Version: 1.0
To: Dave Davey <daved@windclimber.id.au>
Subject: Re: unrtf TextEdit handling
References: <513CE102.2050407@gmail.com> <5172288D.9000805@salk.edu> <20130609130337.GA11079@bandicoot.windclimber.id.au> <51B4BE9F.6020200@salk.edu> <20130614202447.GA14574@bandicoot.windclimber.id.au>
In-Reply-To: <20130614202447.GA14574@bandicoot.windclimber.id.au>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Status: RO
Content-Length: 2436
Lines: 63

Hi Dave, patch below should fix the segfaults; param was not getting set 
correctly coming off the stack.  Also removed an extra strdup that 
seemed to be a leak.  Also one typo correction in unrelated doc.

I would still like to make the improvement I described in previous 
email, to prevent popping and repushing attrs if the desired attr isn't 
anywhere on current stack.  Should have time in the next few days.

Did you figure out whether unnested attrs is within RTF spec?  I suspect 
that it is, but wasn't able to dig into the spec enough to convince myself.

Best,
P


diff -u ../unrtf-0.21.4/src/attr.c src/attr.c
--- ../unrtf-0.21.4/src/attr.c    2013-06-09 05:51:11.096017572 -0700
+++ src/attr.c    2013-06-18 00:34:32.870627598 -0700
@@ -403,7 +403,7 @@
   * Name:    attrstack_unexpress_all
   * Purpose:    Routine to un-express all attributes heretofore applied,
   *         without removing any from the stack.
- * Args:    Stack whost contents should be unexpressed.
+ * Args:    Stack whose contents should be unexpressed.
   * Returns:    None.
   * Notes:    This is needed by attrstack_push, but also for \cell, which
   *         often occurs within a brace group, yet HTML uses <td></td>
@@ -871,15 +871,15 @@
    stack->tos++;
    stack->attr_stack[stack->tos] = attr;
    if (param)
-    stack->attr_stack_params[stack->tos] = my_strdup(param);
+    stack->attr_stack_params[stack->tos] = param;
    else
      stack->attr_stack_params[stack->tos] = NULL;
  }

  // Pop from AttrStack generally, without extra bells and whistles
-void attr_pop_gen(AttrStack *stack, int *attr, char *param) {
+void attr_pop_gen(AttrStack *stack, int *attr, char **param) {
    *attr = stack->attr_stack[stack->tos];
-  param = stack->attr_stack_params[stack->tos];
+  *param = stack->attr_stack_params[stack->tos];
    stack->tos--;
  }

@@ -900,7 +900,7 @@
    // Look for findattr on stack, expressing endings.
    // Store any non-matches to temp_stack
    while (stack->tos >= 0) {
-    attr_pop_gen(stack, &attr, param);
+    attr_pop_gen(stack, &attr, &param);
      attr_express_end(attr, param);
      if (attr == findattr) break;
      attr_push_gen(&temp_stack, attr, param);
@@ -908,7 +908,7 @@

    // Put the non-matches back, expressing beginnings
    while (temp_stack.tos >= 0) {
-    attr_pop_gen(&temp_stack, &attr, param);
+    attr_pop_gen(&temp_stack, &attr, &param);
      attr_push(attr, param);
    }

