From 59350af2697add579d3ecbd5de2d294feb4b371e Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Wed, 13 Mar 2013 13:19:33 +0000 Subject: Fix the code to grab the first line --- tikzit/src/common/TikzGraphAssembler.m | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m index 7f00a1a..8400cf6 100644 --- a/tikzit/src/common/TikzGraphAssembler.m +++ b/tikzit/src/common/TikzGraphAssembler.m @@ -111,12 +111,17 @@ int yywrap() { lineno = 1; tokenpos = 0; NSRange range = [tikz rangeOfString:@"\n"]; - if (![tikz getCString:linebuff - maxLength:500 - encoding:NSUTF8StringEncoding]) { - linebuff[0] = 0; + NSString *firstLine; + if (range.length == 0) { + firstLine = tikz; } else { - linebuff[range.location] = 0; + firstLine = [tikz substringToIndex:range.location]; + } + if (![firstLine getCString:linebuff + maxLength:500 + encoding:NSUTF8StringEncoding]) { + // first line too long; just terminate it at the end of the buffer + linebuff[499] = 0; } NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; -- cgit v1.2.3