diff --git a/source/src/BNFC/Backend/C/CFtoCPrinter.hs b/source/src/BNFC/Backend/C/CFtoCPrinter.hs index b42b67bf..85701121 100644 --- a/source/src/BNFC/Backend/C/CFtoCPrinter.hs +++ b/source/src/BNFC/Backend/C/CFtoCPrinter.hs @@ -270,7 +270,7 @@ mkCFile cf groups = concat [ "void bufEscapeS(const char *s)", "{", - " while (*s) bufEscapeC(*s++);", + " if (s) while (*s) bufEscapeC(*s++);", "}", "void bufEscapeC(const char c)", "{", diff --git a/source/src/BNFC/Backend/CPP/PrettyPrinter.hs b/source/src/BNFC/Backend/CPP/PrettyPrinter.hs index cedd929b..517d89c6 100644 --- a/source/src/BNFC/Backend/CPP/PrettyPrinter.hs +++ b/source/src/BNFC/Backend/CPP/PrettyPrinter.hs @@ -132,7 +132,7 @@ mkHFile useStl inPackage cf groups = unlines "", " void inline bufEscape(const char *s)", " {", - " while (*s) bufEscape(*s++);", + " if (s) while (*s) bufEscape(*s++);", " }", "", if useStl then render (nest 2 $ bufAppendString "bufEscape") else "", diff --git a/source/src/BNFC/Backend/Java/CFtoJavaPrinter15.hs b/source/src/BNFC/Backend/Java/CFtoJavaPrinter15.hs index 3adf9dfc..bc18e599 100644 --- a/source/src/BNFC/Backend/Java/CFtoJavaPrinter15.hs +++ b/source/src/BNFC/Backend/Java/CFtoJavaPrinter15.hs @@ -87,6 +87,7 @@ cf2JavaPrinter packageBase packageAbsyn cf = " private static void printQuoted(String s) { render(\"\\\"\" + escape(s) + \"\\\"\"); }", "", " public static String escape(String s) {", + " if (s == null) return null;", " return s.replace(\"\\\\\", \"\\\\\\\\\")", " .replace(\"\\t\", \"\\\\t\")", " .replace(\"\\b\", \"\\\\b\")",