Changeset ee0500 in git for factory


Ignore:
Timestamp:
Feb 4, 2003, 5:24:59 PM (21 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
d713d78830adcab82fa3ce5686817d1dbdbe140a
Parents:
f9c0d1a7fd1e9511255bd5313bd4ac9de109e42d
Message:
*hannes: avoid buffers of fixed size


git-svn-id: file:///usr/local/Singular/svn/trunk@6471 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/NTLconvert.cc

    rf9c0d1 ree0500  
    1 /* $Id: NTLconvert.cc,v 1.4 2002-10-10 17:43:38 Singular Exp $ */
     1/* $Id: NTLconvert.cc,v 1.5 2003-02-04 16:24:59 Singular Exp $ */
    22#include <config.h>
    33
     
    411411////////////////////////////////////////////////////////////////////////////////
    412412
     413static char *cf_stringtemp=NULL;
     414static char *cf_stringtemp2=NULL;
     415static int cf_stringtemp_l=0;
    413416CanonicalForm convertZZ2CF(ZZ coefficient)
    414417{
    415418  long coeff_long;
    416419  //CanonicalForm tmp=0;
    417   char stringtemp[5000]="";
    418   char stringtemp2[5000]="";
     420  if (cf_stringtemp_l==0)
     421  {
     422    cf_stringtemp=(char *)omAlloc(1023);
     423    cf_stringtemp2=(char *)omAlloc(1023);
     424    cf_stringtemp[0]='\0';
     425    cf_stringtemp2[0]='\0';
     426    cf_stringtemp_l=1023;
     427  }
    419428  char dummy[2];
    420429  int minusremainder=0;
     
    444453    }
    445454
     455    int l=0;
    446456    while (coefficient>9)
    447457    {
     
    452462      //tmp*=10; tmp+=to_long(remaind);
    453463
    454       strcat(stringtemp,dummy);
     464      l++;
     465      if (l>=cf_stringtemp_l-2)
     466      {
     467        omFree(cf_stringtemp2);
     468        char *p=(char *)omAlloc(cf_stringtemp_l*2);
     469        memcpy(p,cf_stringtemp,cf_stringtemp_l);
     470        cf_stringtemp_l*=2;
     471        omFree(cf_stringtemp);
     472        cf_stringtemp=p;
     473        cf_stringtemp2=(char *)omAlloc(cf_stringtemp_l);
     474      }
     475      cf_stringtemp[l-1]=dummy[0];
     476      cf_stringtemp[l]='\0';
     477      //strcat(stringtemp,dummy);
    455478
    456479      coefficient=quotient;
     
    458481    //built up the string in dummy[0]
    459482    dummy[0]=(char)(to_long(coefficient)+'0');
    460     strcat(stringtemp,dummy);
     483    strcat(cf_stringtemp,dummy);
    461484    //tmp*=10; tmp+=to_long(coefficient);
    462485
     
    464487    {
    465488      //Check whether coefficient has been negative at the start of the procedure
    466       stringtemp2[0]='-';
     489      cf_stringtemp2[0]='-';
    467490      //tmp*=(-1);
    468491    }
    469492
    470493    //reverse the list to obtain the correct string
    471     int len=strlen(stringtemp);
     494    int len=strlen(cf_stringtemp);
    472495    for (int i=len-1;i>=0;i--)
    473496    {
    474       stringtemp2[len-i-1+minusremainder]=stringtemp[i];
    475     }
    476     stringtemp2[len+minusremainder]='\0';
     497      cf_stringtemp2[len-i-1+minusremainder]=cf_stringtemp[i];
     498    }
     499    cf_stringtemp2[len+minusremainder]='\0';
    477500  }
    478501
    479502  //convert the string to canonicalform using the char*-Constructor
    480   return CanonicalForm(stringtemp2);
     503  return CanonicalForm(cf_stringtemp2);
    481504  //return tmp;
    482505}
Note: See TracChangeset for help on using the changeset viewer.