From 7965e1bb170e6fe820f5dc2919721c3a9a64721c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Tue, 11 Feb 2003 17:16:01 +0100 Subject: [PATCH] Fixed typo in sscanf("%O") handling. Improved field length handling in sscanf("%O"). Rev: src/opcodes.c:1.138 --- src/opcodes.c | 81 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/opcodes.c b/src/opcodes.c index 78e29c1ade..190cf9e784 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: opcodes.c,v 1.137 2003/02/11 15:22:28 mirar Exp $ +|| $Id: opcodes.c,v 1.138 2003/02/11 16:16:01 grubba Exp $ */ #include "global.h" @@ -30,7 +30,7 @@ #define sp Pike_sp -RCSID("$Id: opcodes.c,v 1.137 2003/02/11 15:22:28 mirar Exp $"); +RCSID("$Id: opcodes.c,v 1.138 2003/02/11 16:16:01 grubba Exp $"); void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind) { @@ -863,18 +863,21 @@ PMOD_EXPORT void f_cast(void) * helper functions for sscanf %O */ -static PMOD_EXPORT int pcharp_extract_char_const(PCHARP str, - PCHARP *dstr, - ptrdiff_t maxlength, - ptrdiff_t *dmaxlength) +static int pcharp_extract_char_const(PCHARP str, + PCHARP *dstr, + ptrdiff_t maxlength, + ptrdiff_t *dmaxlength) { int c; *dstr=str; - maxlength--; - *dmaxlength=maxlength; + *dmaxlength=maxlength-1; - switch (c=EXTRACT_PCHARP(str)) + /* use of macros to keep similar to lexer.h: char_const */ +#define LOOK() (maxlength?INDEX_PCHARP(str,1):0) +#define GETC() (maxlength?(INC_PCHARP(str,1),maxlength--,EXTRACT_PCHARP(str)):0) + + switch (c=GETC()) { case 0: *dmaxlength=maxlength+1; @@ -883,10 +886,6 @@ static PMOD_EXPORT int pcharp_extract_char_const(PCHARP str, case '\\': return '\\'; - /* use of macros to keep similar to lexer.h: char_const */ -#define LOOK() (maxlength?INDEX_PCHARP(str,1):0) -#define GETC() (INC_PCHARP(str,1),INDEX_PCHARP(str,0)) - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': c-='0'; @@ -952,10 +951,10 @@ static PMOD_EXPORT int pcharp_extract_char_const(PCHARP str, return c; } -static PMOD_EXPORT int pcharp_to_svalue_procento(struct svalue *r, - PCHARP str, - PCHARP *dstr, - ptrdiff_t maxlength) +static int pcharp_to_svalue_percent_o(struct svalue *r, + PCHARP str, + PCHARP *dstr, + ptrdiff_t maxlength) { *dstr=str; /* default: no hit */ @@ -1971,31 +1970,31 @@ CHAROPT2( \ INPUT_SHIFT)(input+e,eye-e); \ break; \ \ - case 'O': \ - { \ + case 'O': \ + { \ PIKE_CONCAT(p_wchar, INPUT_SHIFT) *t; \ - PCHARP tmp; \ - if(eye>=input_len) \ - { \ - chars_matched[0]=eye; \ - return matches; \ - } \ - \ - pcharp_to_svalue_procento(&sval, \ - MKPCHARP(input+eye,INPUT_SHIFT), \ - &tmp, \ - field_length); \ - t=(PIKE_CONCAT(p_wchar, INPUT_SHIFT) *)tmp.ptr; \ - if(input + eye == t) \ - { \ - chars_matched[0]=eye; \ - return matches; \ - } \ - eye=t-input; \ - \ - break; \ - } \ - \ + PCHARP tmp; \ + if(eye>=input_len) \ + { \ + chars_matched[0]=eye; \ + return matches; \ + } \ + \ + pcharp_to_svalue_percent_o(&sval, \ + MKPCHARP(input+eye,INPUT_SHIFT), \ + &tmp, \ + field_length); \ + t=(PIKE_CONCAT(p_wchar, INPUT_SHIFT) *)tmp.ptr; \ + if(input + eye == t) \ + { \ + chars_matched[0]=eye; \ + return matches; \ + } \ + eye=t-input; \ + \ + break; \ + } \ + \ case 'n': \ sval.type=T_INT; \ sval.subtype=NUMBER_NUMBER; \ -- GitLab