Continuation() sometimes does not work well in multibyte environment

Jeremy Allison jeremy at valinux.com
Tue Dec 21 03:13:29 GMT 1999


monyo at home.monyo.com wrote:

> I've found a problem in samba-2.0.6 and also latest SAMBA_2_0 CVS Head
> branch. Under Japanese environment, continuation() at
> source/param/params.c sometimes does not work well in multibyte
> environment. Because under some mutibyte environment, an ASCII
> character '\' (0x5c) occurs at a 2nd byte of the 2byte character code
> and Continuation() cannot recognize if a '\' is one ASCII character or
> a 2nd byte of the 2byte character.
> 
> If '\' is a 2nd byte char., we have to treat it as a (part of) normal
> character, not a line-continuation character.
> 
> This problem can occur in "coding system = SJIS" and maybe occur in
> JIS, KS C5601 (7bit), GB 2312, Big5.

This is a correct assessment, but the patch itself has a
few problems.

Here is the version I have committed to the CVS trees (ok,
so I also fixed some of the formatting I *hate* in param/params.c
as well :-).

Regards,

	Jeremy Allison,
	Samba Team.

----------------------cut here--------------------------
Index: param/params.c
===================================================================
RCS file: /data/cvs/samba/source/param/params.c,v
retrieving revision 1.11
diff -u -r1.11 params.c
--- params.c	1998/11/17 20:50:04	1.11
+++ params.c	1999/12/21 02:14:31
@@ -157,28 +157,42 @@
   return( c );
   } /* EatComment */
 
+/*****************************************************************************
+ * Scan backards within a string to discover if the last non-whitespace
+ * character is a line-continuation character ('\\').
+ *
+ *  Input:  line  - A pointer to a buffer containing the string to be
+ *                  scanned.
+ *          pos   - This is taken to be the offset of the end of the
+ *                  string.  This position is *not* scanned.
+ *
+ *  Output: The offset of the '\\' character if it was found, or -1 to
+ *          indicate that it was not.
+ *
+ *****************************************************************************/
+
 static int Continuation( char *line, int pos )
-  /* ------------------------------------------------------------------------ **
-   * Scan backards within a string to discover if the last non-whitespace
-   * character is a line-continuation character ('\\').
-   *
-   *  Input:  line  - A pointer to a buffer containing the string to be
-   *                  scanned.
-   *          pos   - This is taken to be the offset of the end of the
-   *                  string.  This position is *not* scanned.
-   *
-   *  Output: The offset of the '\\' character if it was found, or -1 to
-   *          indicate that it was not.
-   *
-   * ------------------------------------------------------------------------ **
-   */
-  {
+{
+  int pos2 = 0;
+
   pos--;
   while( (pos >= 0) && isspace(line[pos]) )
      pos--;
 
-  return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 );
-  } /* Continuation */
+  /* we should recognize if `\` is part of a multibyte character or not. */
+  while(pos2 <= pos) {
+    size_t skip = 0;
+    skip = skip_multibyte_char(line[pos2]);
+    if (skip) {
+        pos2 += skip;
+    } else if (pos == pos2) {
+        return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 );
+    } else  {
+        pos2++;
+    }
+  }
+  return (-1);
+}
 
 
 static BOOL Section( FILE *InFile, BOOL (*sfunc)(char *) )
----------------------cut here--------------------------
-- 
--------------------------------------------------------
Buying an operating system without source is like buying
a self-assembly Space Shuttle with no instructions.
--------------------------------------------------------


More information about the samba-technical mailing list