Ignore:
Timestamp:
Aug 9, 2023, 5:34:21 PM (11 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
74c6748
Parents:
3318dff
Message:

force all input of C strings to specify a maximum length for the string target

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r3318dff re7a8f65  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug  7 08:59:29 2023
    13 // Update Count     : 1407
     12// Last Modified On : Wed Aug  9 10:10:56 2023
     13// Update Count     : 1432
    1414//
    1515
     
    271271        OSTYPE_VOID_IMPL( const char * )
    272272
    273 //      ostype & ?|?( ostype & os, const char16_t * s ) {
     273//      ostype & ?|?( ostype & os, const char16_t s[] ) {
    274274//              if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    275275//              fmt( os, "%ls", s );
     
    278278
    279279// #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
    280 //      ostype & ?|?( ostype & os, const char32_t * s ) {
     280//      ostype & ?|?( ostype & os, const char32_t s[] ) {
    281281//              if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    282282//              fmt( os, "%ls", s );
     
    285285// #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
    286286
    287 //      ostype & ?|?( ostype & os, const wchar_t * s ) {
     287//      ostype & ?|?( ostype & os, const wchar_t s[] ) {
    288288//              if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    289289//              fmt( os, "%ls", s );
     
    917917        // } // ?|?
    918918
    919         istype & ?|?( istype & is, char s[] ) {
    920                 fmt( is, "%s", s );
    921                 return is;
    922         } // ?|?
    923         ISTYPE_VOID_IMPL( char * )
     919        // istype & ?|?( istype & is, char s[] ) {
     920        //      fmt( is, "%s", s );
     921        //      return is;
     922        // } // ?|?
     923        // ISTYPE_VOID_IMPL( char * )
    924924
    925925        // manipulators
     
    934934        istype & nl( istype & is ) {
    935935                fmt( is, "%*[^\n]" );                                                   // ignore characters to newline
     936                if ( ! eof( is ) && getANL$( is ) ) fmt( is, "%*c" ); // read newline
    936937                return is;
    937938        } // nl
     
    952953forall( istype & | basic_istream( istype ) ) {
    953954        istype & ?|?( istype & is, _Istream_Cstr f ) {
    954                 // skip xxx
     955                // skip
    955956                if ( ! f.s ) {
    956957                        // printf( "skip %s %d\n", f.scanset, f.wd );
    957                         if ( f.wd == -1 ) fmt( is, f.scanset, "" );             // no input arguments
     958                        if ( f.wd == -1 ) fmt( is, f.scanset, "" );     // no input arguments
    958959                        else for ( f.wd ) fmt( is, "%*c" );
    959960                        return is;
    960961                } // if
     962
     963                // getline
     964                if ( f.flags.delimit ) {
     965                        char fmtstr[] = "%[^ ]s";                                       // delimit inserted into space
     966                        fmtstr[3] = f.delimit;
     967                        fmt( is, fmtstr, f.s );                                         // read upto delimiter
     968                        fmt( is, "%*c" );                                                       // ignore delimiter
     969                        return is;
     970                } // if
     971
     972                // incl/excl
    961973                size_t len = 0;
    962974                if ( f.scanset ) len = strlen( f.scanset );
     
    977989                fmtstr[start] = '['; start += 1;
    978990                if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; }
    979                 strcpy( &fmtstr[start], f.scanset );                            // copy includes '\0'
     991                strcpy( &fmtstr[start], f.scanset );                    // copy includes '\0'
    980992                len += start;
    981993                fmtstr[len] = ']'; fmtstr[len + 1] = '\0';
     
    987999
    9881000        istype & ?|?( istype & is, _Istream_Char f ) {
    989                 fmt( is, "%*c" );                                                                       // argument variable unused
     1001                fmt( is, "%*c" );                                                               // argument variable unused
    9901002                return is;
    9911003        } // ?|?
Note: See TracChangeset for help on using the changeset viewer.