summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <alex.merry@cs.ox.ac.uk>2013-03-13 13:19:33 +0000
committerAlex Merry <alex.merry@cs.ox.ac.uk>2013-03-13 13:19:33 +0000
commit59350af2697add579d3ecbd5de2d294feb4b371e (patch)
tree830ea7653e486e3cb0d515af2433b0e74ee8e95d
parent65ecdadd10ce5613eade3aec912f388deadc0b82 (diff)
Fix the code to grab the first line
-rw-r--r--tikzit/src/common/TikzGraphAssembler.m15
1 files 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];