From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Prince Subject: [PATCH] Fix a number of potential infinite loops due to unsgined underflow. Date: Fri, 8 Feb 2013 20:01:37 -0700 Message-ID: <1360378897-22577-1-git-send-email-tom.prince@ualberta.net> Return-path: Received: from eggs.gnu.org ([208.118.235.92]:50234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U40hT-0006qN-R4 for emacs-orgmode@gnu.org; Fri, 08 Feb 2013 22:02:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U40hS-0003cG-Oa for emacs-orgmode@gnu.org; Fri, 08 Feb 2013 22:01:59 -0500 Received: from socrates.hocat.ca ([76.10.188.53]:38812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U40hS-0003bk-Gz for emacs-orgmode@gnu.org; Fri, 08 Feb 2013 22:01:58 -0500 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Andrew Young , emacs-orgmode@gnu.org Cc: Tom Prince I discovered this, when trying to merge a file, with a tag that overhangs the right margin. Trying to merge the following line with itself (with --rmargin less than 10) the causes the driver to output spaces forever: ** abc :TAG: --- src/org_heading.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/org_heading.c b/src/org_heading.c index 264512e..0c58046 100644 --- a/src/org_heading.c +++ b/src/org_heading.c @@ -316,7 +316,7 @@ org_heading_set_entire_text (org_heading *heading, char *string, int length, * This is the whitespace between the stars and heading. * Store it as a substring. */ - for (count = 0; count < ubound - lbound; count++) + for (count = 0; (lbound + count) < ubound; count++) { if (!iswhitespace (string[lbound + count])) { @@ -357,7 +357,7 @@ org_heading_set_entire_text (org_heading *heading, char *string, int length, /* Scan trailing linebreaks * Scan right to left. */ - for (count = 0; count < (ubound - lbound); count++) + for (count = 0; (lbound + count) < ubound; count++) { if (!islinebreak (string[ubound - count - 1])) { @@ -385,7 +385,7 @@ org_heading_set_entire_text (org_heading *heading, char *string, int length, bool foundtags = false; bool done = false; - for (i = 0; i < (ubound - lbound); i++) + for (i = 0; (lbound + i) < ubound; i++) { if (string [ubound - i - 1] == ':') { @@ -397,7 +397,7 @@ org_heading_set_entire_text (org_heading *heading, char *string, int length, debug_msg (DOC_ELT, 5, "Setting tags_ubound =%d\n", tags_ubound); } int j; - for (j = 2; j < (tags_ubound - lbound); j++) + for (j = 2; (lbound + j) < tags_ubound; j++) { if (iswhitespace (string[tags_ubound - j])) { @@ -1902,7 +1902,7 @@ merge_tags (substr anc_str, substr loc_str, substr rem_str, size_t curr_col, int i; doc_stream_putc(' ', out); //curr_col += 1; - for (i=0; i < (ctxt->rmargin - 1 - char_count - curr_col); i++) + for (i=0; 1 + char_count + curr_col + i < ctxt->rmargin; i++) { doc_stream_putc(' ', out); } -- 1.8.0.2