tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / basic / source / sbx / sbxint.cxx
blob6a6721eb78404f3b0f6b9280fa6036e3921afcfd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <o3tl/safeint.hxx>
23 #include <comphelper/errcode.hxx>
24 #include <basic/sberrors.hxx>
25 #include "sbxconv.hxx"
27 #include <rtl/math.hxx>
29 sal_Int16 ImpGetInteger( const SbxValues* p )
31 SbxValues aTmp;
32 sal_Int16 nRes;
33 start:
34 switch( +p->eType )
36 case SbxNULL:
37 SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
38 [[fallthrough]];
39 case SbxEMPTY:
40 nRes = 0; break;
41 case SbxCHAR:
42 nRes = p->nChar; break;
43 case SbxBYTE:
44 nRes = p->nByte; break;
45 case SbxINTEGER:
46 case SbxBOOL:
47 nRes = p->nInteger; break;
48 case SbxERROR:
49 case SbxUSHORT:
50 if( p->nUShort > o3tl::make_unsigned(SbxMAXINT) )
52 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
54 else
55 nRes = static_cast<sal_Int16>(p->nUShort);
56 break;
57 case SbxLONG:
58 if( p->nLong > SbxMAXINT )
60 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
62 else if( p->nLong < SbxMININT )
64 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMININT;
66 else
67 nRes = static_cast<sal_Int16>(p->nLong);
68 break;
69 case SbxULONG:
70 if( p->nULong > SbxMAXINT )
72 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
74 else
75 nRes = static_cast<sal_Int16>(p->nULong);
76 break;
77 case SbxSINGLE:
78 nRes = ImpDoubleToInteger(p->nSingle);
79 break;
80 case SbxCURRENCY:
81 nRes = CurTo<sal_Int16>(p->nInt64);
82 break;
83 case SbxSALINT64:
84 if( p->nInt64 > SbxMAXINT )
86 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
88 else if( p->nInt64 < SbxMININT )
90 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMININT;
92 else
93 nRes = static_cast<sal_Int16>(p->nInt64);
94 break;
95 case SbxSALUINT64:
96 if( p->uInt64 > SbxMAXINT )
98 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
100 else
101 nRes = static_cast<sal_Int16>(p->uInt64);
102 break;
103 case SbxDATE:
104 case SbxDOUBLE:
105 case SbxDECIMAL:
106 case SbxBYREF | SbxDECIMAL:
108 double dVal = 0.0;
109 if( p->eType == SbxDECIMAL )
111 if( p->pDecimal )
112 p->pDecimal->getDouble( dVal );
114 else
115 dVal = p->nDouble;
117 nRes = ImpDoubleToInteger(dVal);
118 break;
120 case SbxLPSTR:
121 case SbxSTRING:
122 case SbxBYREF | SbxSTRING:
123 if( !p->pOUString )
124 nRes = 0;
125 else
127 double d;
128 SbxDataType t;
129 if( ImpScan( *p->pOUString, d, t, nullptr ) != ERRCODE_NONE )
130 nRes = 0;
131 else
132 nRes = ImpDoubleToInteger(d);
134 break;
135 case SbxOBJECT:
137 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
138 if( pVal )
139 nRes = pVal->GetInteger();
140 else
142 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
144 break;
147 case SbxBYREF | SbxCHAR:
148 nRes = *p->pChar; break;
149 case SbxBYREF | SbxBYTE:
150 nRes = *p->pByte; break;
151 case SbxBYREF | SbxINTEGER:
152 case SbxBYREF | SbxBOOL:
153 nRes = *p->pInteger; break;
155 // from here had to be tested
156 case SbxBYREF | SbxLONG:
157 aTmp.nLong = *p->pLong; goto ref;
158 case SbxBYREF | SbxULONG:
159 aTmp.nULong = *p->pULong; goto ref;
160 case SbxBYREF | SbxERROR:
161 case SbxBYREF | SbxUSHORT:
162 aTmp.nUShort = *p->pUShort; goto ref;
163 case SbxBYREF | SbxSINGLE:
164 aTmp.nSingle = *p->pSingle; goto ref;
165 case SbxBYREF | SbxDATE:
166 case SbxBYREF | SbxDOUBLE:
167 aTmp.nDouble = *p->pDouble; goto ref;
168 case SbxBYREF | SbxCURRENCY:
169 case SbxBYREF | SbxSALINT64:
170 aTmp.nInt64 = *p->pnInt64; goto ref;
171 case SbxBYREF | SbxSALUINT64:
172 aTmp.uInt64 = *p->puInt64; goto ref;
173 ref:
174 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
175 p = &aTmp; goto start;
177 default:
178 SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
180 return nRes;
183 void ImpPutInteger( SbxValues* p, sal_Int16 n )
185 SbxValues aTmp;
186 start:
187 switch( +p->eType )
189 // here had to be tested
190 case SbxCHAR:
191 aTmp.pChar = &p->nChar; goto direct;
192 case SbxBYTE:
193 aTmp.pByte = &p->nByte; goto direct;
194 case SbxULONG:
195 aTmp.pULong = &p->nULong; goto direct;
196 case SbxERROR:
197 case SbxUSHORT:
198 aTmp.pUShort = &p->nUShort; goto direct;
199 case SbxSALUINT64:
200 aTmp.puInt64 = &p->uInt64; goto direct;
201 direct:
202 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
203 p = &aTmp; goto start;
205 // from here no tests needed
206 case SbxINTEGER:
207 case SbxBOOL:
208 p->nInteger = n; break;
209 case SbxLONG:
210 p->nLong = n; break;
211 case SbxSINGLE:
212 p->nSingle = n; break;
213 case SbxDATE:
214 case SbxDOUBLE:
215 p->nDouble = n; break;
216 case SbxCURRENCY:
217 p->nInt64 = CurFrom(n); break;
218 case SbxSALINT64:
219 p->nInt64 = n; break;
220 case SbxDECIMAL:
221 case SbxBYREF | SbxDECIMAL:
222 ImpCreateDecimal( p )->setInt( n );
223 break;
225 case SbxLPSTR:
226 case SbxSTRING:
227 case SbxBYREF | SbxSTRING:
228 if( !p->pOUString )
229 p->pOUString = new OUString;
230 ImpCvtNum( static_cast<double>(n), 0, *p->pOUString );
231 break;
232 case SbxOBJECT:
234 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
235 if( pVal )
236 pVal->PutInteger( n );
237 else
238 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
239 break;
241 case SbxBYREF | SbxCHAR:
242 if( n < SbxMINCHAR )
244 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCHAR;
246 *p->pChar = static_cast<char>(n); break;
247 case SbxBYREF | SbxBYTE:
248 if( n > SbxMAXBYTE )
250 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE;
252 else if( n < 0 )
254 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
256 *p->pByte = static_cast<sal_uInt8>(n); break;
257 case SbxBYREF | SbxINTEGER:
258 case SbxBYREF | SbxBOOL:
259 *p->pInteger = n; break;
260 case SbxBYREF | SbxERROR:
261 case SbxBYREF | SbxUSHORT:
262 if( n < 0 )
264 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
266 *p->pUShort = static_cast<sal_uInt16>(n); break;
267 case SbxBYREF | SbxLONG:
268 *p->pLong = static_cast<sal_Int32>(n); break;
269 case SbxBYREF | SbxULONG:
270 if( n < 0 )
272 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
274 *p->pULong = static_cast<sal_uInt32>(n); break;
275 case SbxBYREF | SbxCURRENCY:
276 *p->pnInt64 = CurFrom(n); break;
277 case SbxBYREF | SbxSALINT64:
278 *p->pnInt64 = n; break;
279 case SbxBYREF | SbxSALUINT64:
280 if( n < 0 )
282 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
283 *p->puInt64 = 0;
285 else
286 *p->puInt64 = n;
287 break;
288 case SbxBYREF | SbxSINGLE:
289 *p->pSingle = static_cast<float>(n); break;
290 case SbxBYREF | SbxDATE:
291 case SbxBYREF | SbxDOUBLE:
292 *p->pDouble = static_cast<double>(n); break;
294 default:
295 SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
300 // sal_Int64 / hyper
302 double ImpSalUInt64ToDouble( sal_uInt64 n )
304 double d = 0.0;
305 if( n > SAL_MAX_INT64 )
306 SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
307 else
308 d = static_cast<double>(static_cast<sal_Int64>(n));
309 return d;
313 sal_Int64 ImpGetInt64( const SbxValues* p )
315 SbxValues aTmp;
316 sal_Int64 nRes;
317 start:
318 switch( +p->eType )
320 case SbxNULL:
321 SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
322 [[fallthrough]];
323 case SbxEMPTY:
324 nRes = 0; break;
325 case SbxCHAR:
326 nRes = p->nChar; break;
327 case SbxBYTE:
328 nRes = p->nByte; break;
329 case SbxINTEGER:
330 case SbxBOOL:
331 nRes = p->nInteger; break;
332 case SbxERROR:
333 case SbxUSHORT:
334 nRes = static_cast<sal_Int64>(p->nUShort); break;
335 case SbxLONG:
336 nRes = static_cast<sal_Int64>(p->nLong); break;
337 case SbxULONG:
338 nRes = static_cast<sal_Int64>(p->nULong); break;
339 case SbxSINGLE:
340 nRes = ImpDoubleToSalInt64(p->nSingle);
341 break;
342 case SbxDATE:
343 case SbxDOUBLE:
344 nRes = ImpDoubleToSalInt64(p->nDouble);
345 break;
346 case SbxCURRENCY:
347 nRes = CurTo<sal_Int64>(p->nInt64); break;
348 case SbxSALINT64:
349 nRes = p->nInt64; break;
350 case SbxSALUINT64:
351 if( p->uInt64 > SAL_MAX_INT64 )
353 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SAL_MAX_INT64;
355 else
356 nRes = static_cast<sal_Int64>(p->uInt64);
357 break;
359 case SbxBYREF | SbxSTRING:
360 case SbxSTRING:
361 case SbxLPSTR:
362 if( !p->pOUString )
363 nRes = 0;
364 else
366 nRes = p->pOUString->toInt64();
367 if( nRes == 0 )
369 // Check if really 0 or invalid conversion
370 double d;
371 SbxDataType t;
372 if( ImpScan( *p->pOUString, d, t, nullptr ) != ERRCODE_NONE )
373 nRes = 0;
374 else
375 nRes = ImpDoubleToSalInt64(d);
378 break;
379 case SbxOBJECT:
381 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
382 if( pVal )
383 nRes = pVal->GetInt64();
384 else
386 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
388 break;
391 case SbxBYREF | SbxCHAR:
392 nRes = *p->pChar; break;
393 case SbxBYREF | SbxBYTE:
394 nRes = *p->pByte; break;
395 case SbxBYREF | SbxINTEGER:
396 case SbxBYREF | SbxBOOL:
397 nRes = *p->pInteger; break;
398 case SbxBYREF | SbxLONG:
399 nRes = *p->pLong; break;
400 case SbxBYREF | SbxULONG:
401 nRes = *p->pULong; break;
402 case SbxBYREF | SbxCURRENCY:
403 nRes = CurTo<sal_Int64>(*p->pnInt64); break;
404 case SbxBYREF | SbxSALINT64:
405 nRes = *p->pnInt64; break;
407 // from here the values has to be checked
408 case SbxBYREF | SbxSALUINT64:
409 aTmp.uInt64 = *p->puInt64; goto ref;
411 case SbxBYREF | SbxERROR:
412 case SbxBYREF | SbxUSHORT:
413 aTmp.nUShort = *p->pUShort; goto ref;
414 case SbxBYREF | SbxSINGLE:
415 aTmp.nSingle = *p->pSingle; goto ref;
416 case SbxBYREF | SbxDATE:
417 case SbxBYREF | SbxDOUBLE:
418 aTmp.nDouble = *p->pDouble; goto ref;
419 ref:
420 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
421 p = &aTmp; goto start;
423 default:
424 SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
426 return nRes;
429 void ImpPutInt64( SbxValues* p, sal_Int64 n )
431 SbxValues aTmp;
433 start:
434 switch( +p->eType )
436 // Check necessary
437 case SbxCHAR:
438 aTmp.pChar = &p->nChar; goto direct;
439 case SbxBYTE:
440 aTmp.pByte = &p->nByte; goto direct;
441 case SbxINTEGER:
442 case SbxBOOL:
443 aTmp.pInteger = &p->nInteger; goto direct;
444 case SbxULONG:
445 aTmp.pULong = &p->nULong; goto direct;
446 case SbxERROR:
447 case SbxUSHORT:
448 aTmp.pUShort = &p->nUShort; goto direct;
449 case SbxLONG:
450 aTmp.pnInt64 = &p->nInt64; goto direct;
451 case SbxCURRENCY:
452 case SbxSALINT64:
453 aTmp.pnInt64 = &p->nInt64; goto direct;
454 case SbxSALUINT64:
455 aTmp.puInt64 = &p->uInt64; goto direct;
457 direct:
458 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
459 p = &aTmp; goto start;
461 case SbxSINGLE:
462 p->nSingle = static_cast<float>(n); break;
463 case SbxDATE:
464 case SbxDOUBLE:
465 p->nDouble = static_cast<double>(n); break;
467 case SbxBYREF | SbxSTRING:
468 case SbxSTRING:
469 case SbxLPSTR:
471 if( !p->pOUString )
472 p->pOUString = new OUString;
474 (*p->pOUString) = OUString::number(n);
475 break;
477 case SbxOBJECT:
479 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
480 if( pVal )
481 pVal->PutInt64( n );
482 else
483 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
484 break;
486 case SbxBYREF | SbxCHAR:
487 if( n > SbxMAXCHAR )
489 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCHAR;
491 else if( n < SbxMINCHAR )
493 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCHAR;
495 *p->pChar = static_cast<sal_Unicode>(n); break;
496 case SbxBYREF | SbxBYTE:
497 if( n > SbxMAXBYTE )
499 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE;
501 else if( n < 0 )
503 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
505 *p->pByte = static_cast<sal_uInt8>(n); break;
506 case SbxBYREF | SbxINTEGER:
507 case SbxBYREF | SbxBOOL:
508 if( n > SbxMAXINT )
510 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXINT;
512 else if( n < SbxMININT )
514 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMININT;
516 *p->pInteger = static_cast<sal_Int16>(n); break;
517 case SbxBYREF | SbxERROR:
518 case SbxBYREF | SbxUSHORT:
519 if( n > SbxMAXUINT )
521 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXUINT;
523 else if( n < 0 )
525 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
527 *p->pUShort = static_cast<sal_uInt16>(n); break;
528 case SbxBYREF | SbxLONG:
529 if( n > SbxMAXLNG )
531 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXLNG;
533 else if( n < SbxMINLNG )
535 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINLNG;
537 *p->pLong = static_cast<sal_Int32>(n); break;
538 case SbxBYREF | SbxULONG:
539 if( n > SbxMAXULNG )
541 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXULNG;
543 else if( n < 0 )
545 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
547 *p->pULong = static_cast<sal_uInt32>(n); break;
548 case SbxBYREF | SbxSINGLE:
549 *p->pSingle = static_cast<float>(n); break;
550 case SbxBYREF | SbxDATE:
551 case SbxBYREF | SbxDOUBLE:
552 *p->pDouble = static_cast<double>(n); break;
553 case SbxBYREF | SbxCURRENCY:
554 *p->pnInt64 = CurFrom(n); break;
555 case SbxBYREF | SbxSALINT64:
556 *p->pnInt64 = n; break;
557 case SbxBYREF | SbxSALUINT64:
558 if( n < 0 )
560 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
562 *p->puInt64 = n; break;
564 default:
565 SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
569 sal_uInt64 ImpGetUInt64( const SbxValues* p )
571 SbxValues aTmp;
572 sal_uInt64 nRes;
573 start:
574 switch( +p->eType )
576 case SbxNULL:
577 SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
578 [[fallthrough]];
579 case SbxEMPTY:
580 nRes = 0; break;
581 case SbxCHAR:
582 nRes = p->nChar; break;
583 case SbxBYTE:
584 nRes = p->nByte; break;
585 case SbxINTEGER:
586 case SbxBOOL:
587 nRes = p->nInteger; break;
588 case SbxERROR:
589 case SbxUSHORT:
590 nRes = p->nUShort; break;
591 case SbxLONG:
592 nRes = p->nLong; break;
593 case SbxULONG:
594 nRes = static_cast<sal_uInt64>(p->nULong); break;
595 case SbxSINGLE:
596 nRes = ImpDoubleToSalUInt64(p->nSingle); break;
597 case SbxDATE:
598 case SbxDOUBLE:
599 nRes = ImpDoubleToSalUInt64(p->nDouble);
600 break;
601 case SbxCURRENCY:
602 nRes = CurFrom(p->nInt64); break;
603 case SbxSALINT64:
604 if( p->nInt64 < 0 )
606 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
608 else
609 nRes = static_cast<sal_uInt64>(p->nInt64);
610 break;
611 case SbxSALUINT64:
612 nRes = p->uInt64; break;
614 case SbxBYREF | SbxSTRING:
615 case SbxSTRING:
616 case SbxLPSTR:
617 if( !p->pOUString )
618 nRes = 0;
619 else
621 nRes = p->pOUString->toUInt64();
622 if( nRes == 0 )
624 // Check if really 0 or invalid conversion
625 double d;
626 SbxDataType t;
627 if( ImpScan( *p->pOUString, d, t, nullptr ) != ERRCODE_NONE )
628 nRes = 0;
629 else
630 nRes = ImpDoubleToSalUInt64(d);
633 break;
634 case SbxOBJECT:
636 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
637 if( pVal )
638 nRes = pVal->GetUInt64();
639 else
641 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
643 break;
646 case SbxBYREF | SbxCHAR:
647 nRes = *p->pChar; break;
648 case SbxBYREF | SbxBYTE:
649 nRes = *p->pByte; break;
650 case SbxBYREF | SbxINTEGER:
651 case SbxBYREF | SbxBOOL:
652 nRes = *p->pInteger; break;
653 case SbxBYREF | SbxLONG:
654 nRes = *p->pLong; break;
655 case SbxBYREF | SbxULONG:
656 nRes = *p->pULong; break;
657 case SbxBYREF | SbxSALUINT64:
658 nRes = *p->puInt64; break;
660 // from here on the value has to be checked
661 case SbxBYREF | SbxERROR:
662 case SbxBYREF | SbxUSHORT:
663 aTmp.nUShort = *p->pUShort; goto ref;
664 case SbxBYREF | SbxSINGLE:
665 aTmp.nSingle = *p->pSingle; goto ref;
666 case SbxBYREF | SbxDATE:
667 case SbxBYREF | SbxDOUBLE:
668 aTmp.nDouble = *p->pDouble; goto ref;
669 case SbxBYREF | SbxCURRENCY:
670 case SbxBYREF | SbxSALINT64:
671 aTmp.nInt64 = *p->pnInt64; goto ref;
672 ref:
673 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
674 p = &aTmp; goto start;
676 default:
677 SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
679 return nRes;
682 void ImpPutUInt64( SbxValues* p, sal_uInt64 n )
684 SbxValues aTmp;
686 start:
687 switch( +p->eType )
689 // Check necessary
690 case SbxCHAR:
691 aTmp.pChar = &p->nChar; goto direct;
692 case SbxBYTE:
693 aTmp.pByte = &p->nByte; goto direct;
694 case SbxINTEGER:
695 case SbxBOOL:
696 aTmp.pInteger = &p->nInteger; goto direct;
697 case SbxULONG:
698 aTmp.pULong = &p->nULong; goto direct;
699 case SbxERROR:
700 case SbxUSHORT:
701 aTmp.pUShort = &p->nUShort; goto direct;
702 case SbxLONG:
703 aTmp.pnInt64 = &p->nInt64; goto direct;
704 case SbxCURRENCY:
705 case SbxSALINT64:
706 aTmp.pnInt64 = &p->nInt64; goto direct;
707 case SbxSINGLE:
708 aTmp.pSingle = &p->nSingle; goto direct;
709 case SbxDATE:
710 case SbxDOUBLE:
711 aTmp.pDouble = &p->nDouble; goto direct;
713 direct:
714 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
715 p = &aTmp; goto start;
717 // Check not necessary
718 case SbxSALUINT64:
719 p->uInt64 = n; break;
721 case SbxBYREF | SbxSTRING:
722 case SbxSTRING:
723 case SbxLPSTR:
724 if( !p->pOUString )
725 p->pOUString = new OUString;
726 if( n > SAL_MAX_INT64 )
727 SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
728 else
730 (*p->pOUString) = OUString::number(n);
732 break;
733 case SbxOBJECT:
735 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
736 if( pVal )
737 pVal->PutUInt64( n );
738 else
739 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
740 break;
742 case SbxBYREF | SbxCHAR:
743 if( n > SbxMAXCHAR )
745 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCHAR;
747 *p->pChar = static_cast<sal_Unicode>(n); break;
748 case SbxBYREF | SbxBYTE:
749 if( n > SbxMAXBYTE )
751 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE;
753 *p->pByte = static_cast<sal_uInt8>(n); break;
754 case SbxBYREF | SbxINTEGER:
755 case SbxBYREF | SbxBOOL:
756 if( n > SbxMAXINT )
758 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXINT;
760 *p->pInteger = static_cast<sal_Int16>(n); break;
761 case SbxBYREF | SbxERROR:
762 case SbxBYREF | SbxUSHORT:
763 if( n > SbxMAXUINT )
765 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXUINT;
767 *p->pUShort = static_cast<sal_uInt16>(n); break;
768 case SbxBYREF | SbxLONG:
769 if( n > SbxMAXLNG )
771 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXLNG;
773 *p->pLong = static_cast<sal_Int32>(n); break;
774 case SbxBYREF | SbxULONG:
775 if( n > SbxMAXULNG )
777 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXULNG;
779 *p->pULong = static_cast<sal_uInt32>(n); break;
780 case SbxBYREF | SbxSINGLE:
781 *p->pDouble = static_cast<float>(ImpSalUInt64ToDouble( n )); break;
782 case SbxBYREF | SbxDATE:
783 case SbxBYREF | SbxDOUBLE:
785 *p->pDouble = ImpSalUInt64ToDouble( n ); break;
786 case SbxBYREF | SbxCURRENCY:
787 *p->pnInt64 = CurFrom(n);
788 break;
789 case SbxBYREF | SbxSALUINT64:
790 *p->puInt64 = n; break;
791 case SbxBYREF | SbxSALINT64:
792 if( n > SAL_MAX_INT64 )
794 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
796 *p->pnInt64 = static_cast<sal_Int64>(n); break;
798 default:
799 SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
804 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */