Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%42s uses sv_pos_b2u/sv_pos_u2b #10168

Open
p5pRT opened this issue Feb 13, 2010 · 4 comments
Open

%42s uses sv_pos_b2u/sv_pos_u2b #10168

p5pRT opened this issue Feb 13, 2010 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 13, 2010

Migrated from rt.perl.org#72776 (status was 'new')

Searchable as RT72776$

@p5pRT
Copy link
Author

p5pRT commented Feb 13, 2010

From @nwc10

sv.c
9837​: sv_pos_u2b(argsv, &p, 0); /* sticks at end */

This is deep in the bowls of printf​:

  case 's'​:
  if (vectorize)
  goto unknown;
  if (args) {
  eptr = va_arg(*args, char*);
  if (eptr)
  elen = strlen(eptr);
  else {
  eptr = (char *)nullstr;
  elen = sizeof nullstr - 1;
  }
  }
  else {
  eptr = SvPV_const(argsv, elen);
  if (DO_UTF8(argsv)) {
  STRLEN old_precis = precis;
  if (has_precis && precis < elen) {
  STRLEN ulen = sv_len_utf8(argsv);
  I32 p = precis > ulen ? ulen : precis;
  sv_pos_u2b(argsv, &p, 0); /* sticks at end */
  precis = p;
  }
  if (width) { /* fudge width (can't fudge elen) */
  if (has_precis && precis < elen)
  width += precis - old_precis;
  else
  width += elen - sv_len_utf8(argsv);
  }
  is_utf8 = TRUE;
  }
  }

I *think* all the surroundings translate as %s, but with a length constraint,
eg %42s, where the constraint is less than the (octed) length of a UTF-8
string. In which case, work out where the 42nd character goes up to.

So, %2147483648s and similar aren't going to work (well) on UTF-8 strings
over 2GB.

Nicholas Clark

1 similar comment
@p5pRT
Copy link
Author

p5pRT commented Feb 13, 2010

From @nwc10

sv.c
9837​: sv_pos_u2b(argsv, &p, 0); /* sticks at end */

This is deep in the bowls of printf​:

  case 's'​:
  if (vectorize)
  goto unknown;
  if (args) {
  eptr = va_arg(*args, char*);
  if (eptr)
  elen = strlen(eptr);
  else {
  eptr = (char *)nullstr;
  elen = sizeof nullstr - 1;
  }
  }
  else {
  eptr = SvPV_const(argsv, elen);
  if (DO_UTF8(argsv)) {
  STRLEN old_precis = precis;
  if (has_precis && precis < elen) {
  STRLEN ulen = sv_len_utf8(argsv);
  I32 p = precis > ulen ? ulen : precis;
  sv_pos_u2b(argsv, &p, 0); /* sticks at end */
  precis = p;
  }
  if (width) { /* fudge width (can't fudge elen) */
  if (has_precis && precis < elen)
  width += precis - old_precis;
  else
  width += elen - sv_len_utf8(argsv);
  }
  is_utf8 = TRUE;
  }
  }

I *think* all the surroundings translate as %s, but with a length constraint,
eg %42s, where the constraint is less than the (octed) length of a UTF-8
string. In which case, work out where the 42nd character goes up to.

So, %2147483648s and similar aren't going to work (well) on UTF-8 strings
over 2GB.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Sep 16, 2010

From @cpansprout

Exact copy of 72776.

@p5pRT
Copy link
Author

p5pRT commented Sep 16, 2010

@cpansprout - Status changed from 'new' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants