Changeset 8cffa4f for libcfa


Ignore:
Timestamp:
Oct 5, 2023, 2:30:54 PM (7 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
b67b632
Parents:
bf1cbde
Message:

Support match-failure reporting for string input.

On failed match, assign the empty-string value to the target.
Prior handling did not modify the target,
which in context like char s[10]; sin | exclude("\n", s);,
left s uninitialized, and invalid for strlen, when the input's next character is a newline.
In this case, scanf offers the return value, the count of output arguments written,
to say, "I did not write to your buffer," a feature lost in the pipe abstraction.

Add tests to exercise such cases.

(Prior "leave uninitialized" treatment was discovered by surprise, while debugging a test program for an upcoming commit.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    rbf1cbde r8cffa4f  
    10111011
    10121012                int check = f.wd - 2;
    1013                 if ( ! f.flags.rwd ) f.s[check] = '\0';                 // insert sentinel
     1013                if (! f.flags.ignore ) {
     1014                        f.s[0] = '\0';
     1015                        if ( ! f.flags.rwd ) f.s[check] = '\0';         // insert sentinel
     1016                }
    10141017                len = fmt( is, fmtstr, f.s );
    10151018                //fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, f.s[check], f.s );
    10161019
    1017                 if ( ! f.flags.rwd && f.s[check] != '\0' )              // sentinel overwritten ?
     1020                if (! f.flags.ignore && ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ?
    10181021                        throw (cstring_length){ &cstring_length_vt };
    10191022
Note: See TracChangeset for help on using the changeset viewer.