Index: osprey/be/cg/cgdwarf.cxx
===================================================================
--- osprey/be/cg/cgdwarf.cxx	(revision 3737)
+++ osprey/be/cg/cgdwarf.cxx	(working copy)
@@ -2895,8 +2895,12 @@
     for (i = cur_file->max_line_printed; i < USRCPOS_linenum(usrcpos); i++) {
       if (fgets (text, sizeof(text), cur_file->fileptr) != NULL) {
 	// check for really long line
-       if (strlen(text) >= 1023) text[1022] = '\n';
-#if defined(TARG_SL)
+	int len = strlen(text);
+	if (len >= sizeof(text)-1) 
+	  text[sizeof(text)-2] = '\n';
+
+        // This also may happen when "no newline at the end of the file." 
+
         // Fixed a source information bug with IPA turn on. When turning on
         // IPA there is no '\n' after source line info "#endif\0", but correct
         // content should be "#endif\n\0". This will cause real instruction
@@ -2906,11 +2910,11 @@
         //     mv16 $4, $0
         // With IPA:
         //   #endif mv16 $4, $0
-        if (text[strlen(text)-1] != '\n') {
-          text[strlen(text)+1] = '\0';
-          text[strlen(text)] = '\n';
+        if (len == 0 || text[len-1] != '\n') {
+          text[len] = '\n';
+          text[len+1] = '\0';
         }
-#endif
+
         fprintf (Asm_File, "%s%4d  %s", ASM_CMNT_LINE, i+1, text);
       }
     }
