Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1502#discussion_r179546844
  
    --- Diff: core/sql/optimizer/ValueDesc.cpp ---
    @@ -6381,35 +6380,47 @@ void ValueIdList::convertToTextKey(const 
ValueIdList& keyList, NAString& result)
         }
            else
         {
    -      short vLen = val.length();
    +           short vLen = val.length();
     
           if ((constType->getTypeQualifier()  == NA_NUMERIC_TYPE) &&
               (((NumericType*)constType)->isExact()) &&
    -               (NOT ((NumericType&)type).isBigNum()) &&
    +               (NOT ((NumericType*)constType)->isBigNum()) &&
               (constType->getScale() > 0))
             {
    -          NAString newVal;
    -          if (vLen <= constType->getScale())
    -            {
    -              newVal = "0.";
    -              for (Lng32 i = 0; i < (constType->getScale() - vLen); i++)
    -                {
    -                  newVal += "0";
    -                }
    -              newVal += val;
    -            }
    -          else
    -            {
    -                   // get digits to the left of scale
    -              newVal = val(0, vLen - constType->getScale() );
    -
    -              newVal += ".";
    -              newVal += val(vLen - constType->getScale(), 
constType->getScale());
    -            }
    +               // See how many positions the result will take in the 
display
    +               Lng32 t = 
constType->getDisplayLength(constType->getFSDatatype(),
    +                                               constType->getNominalSize(),
    +                                               constType->getPrecision(),
    +                                               constType->getScale(),
    +                                               0);
    +
    +               char strval[100];
    --- End diff --
    
    If you make this "char strval[t+1]" you will be guaranteed that you will 
never have a buffer overrun here.


---

Reply via email to