TianoCore EDK2 master
Loading...
Searching...
No Matches
SafeIntLib32.c
Go to the documentation of this file.
1
12#include <Base.h>
13#include <Library/SafeIntLib.h>
14#include <Library/BaseLib.h>
15
36RETURN_STATUS
37EFIAPI
39 IN INT32 Operand,
40 OUT UINTN *Result
41 )
42{
43 return SafeInt32ToUint32 (Operand, (UINT32 *)Result);
44}
45
66RETURN_STATUS
67EFIAPI
69 IN UINT32 Operand,
70 OUT INTN *Result
71 )
72{
73 return SafeUint32ToInt32 (Operand, (INT32 *)Result);
74}
75
96RETURN_STATUS
97EFIAPI
99 IN INTN Operand,
100 OUT INT32 *Result
101 )
102{
103 if (Result == NULL) {
105 }
106
107 *Result = (INT32)Operand;
108 return RETURN_SUCCESS;
109}
110
131RETURN_STATUS
132EFIAPI
134 IN INTN Operand,
135 OUT UINT32 *Result
136 )
137{
138 RETURN_STATUS Status;
139
140 if (Result == NULL) {
142 }
143
144 if (Operand >= 0) {
145 *Result = (UINT32)Operand;
146 Status = RETURN_SUCCESS;
147 } else {
148 *Result = UINT32_ERROR;
150 }
151
152 return Status;
153}
154
175RETURN_STATUS
176EFIAPI
178 IN UINTN Operand,
179 OUT UINT32 *Result
180 )
181{
182 if (Result == NULL) {
184 }
185
186 *Result = (UINT32)Operand;
187 return RETURN_SUCCESS;
188}
189
210RETURN_STATUS
211EFIAPI
213 IN UINTN Operand,
214 OUT INT64 *Result
215 )
216{
217 if (Result == NULL) {
219 }
220
221 *Result = (INT64)Operand;
222 return RETURN_SUCCESS;
223}
224
245RETURN_STATUS
246EFIAPI
248 IN INT64 Operand,
249 OUT INTN *Result
250 )
251{
252 return SafeInt64ToInt32 (Operand, (INT32 *)Result);
253}
254
275RETURN_STATUS
276EFIAPI
278 IN INT64 Operand,
279 OUT UINTN *Result
280 )
281{
282 return SafeInt64ToUint32 (Operand, (UINT32 *)Result);
283}
284
305RETURN_STATUS
306EFIAPI
308 IN UINT64 Operand,
309 OUT UINTN *Result
310 )
311{
312 return SafeUint64ToUint32 ((UINT64)Operand, (UINT32 *)Result);
313}
314
336RETURN_STATUS
337EFIAPI
339 IN UINTN Augend,
340 IN UINTN Addend,
341 OUT UINTN *Result
342 )
343{
344 RETURN_STATUS Status;
345
346 if (Result == NULL) {
348 }
349
350 if ((Augend + Addend) >= Augend) {
351 *Result = (Augend + Addend);
352 Status = RETURN_SUCCESS;
353 } else {
354 *Result = UINTN_ERROR;
356 }
357
358 return Status;
359}
360
382RETURN_STATUS
383EFIAPI
385 IN UINTN Minuend,
386 IN UINTN Subtrahend,
387 OUT UINTN *Result
388 )
389{
390 RETURN_STATUS Status;
391
392 if (Result == NULL) {
394 }
395
396 if (Minuend >= Subtrahend) {
397 *Result = (Minuend - Subtrahend);
398 Status = RETURN_SUCCESS;
399 } else {
400 *Result = UINTN_ERROR;
402 }
403
404 return Status;
405}
406
428RETURN_STATUS
429EFIAPI
431 IN UINTN Multiplicand,
432 IN UINTN Multiplier,
433 OUT UINTN *Result
434 )
435{
436 UINT64 IntermediateResult;
437
438 IntermediateResult = ((UINT64)Multiplicand) *((UINT64)Multiplier);
439
440 return SafeUint64ToUintn (IntermediateResult, Result);
441}
442
464RETURN_STATUS
465EFIAPI
467 IN INTN Augend,
468 IN INTN Addend,
469 OUT INTN *Result
470 )
471{
472 return SafeInt64ToIntn (((INT64)Augend) + ((INT64)Addend), Result);
473}
474
496RETURN_STATUS
497EFIAPI
499 IN INTN Minuend,
500 IN INTN Subtrahend,
501 OUT INTN *Result
502 )
503{
504 return SafeInt64ToIntn (((INT64)Minuend) - ((INT64)Subtrahend), Result);
505}
506
528RETURN_STATUS
529EFIAPI
531 IN INTN Multiplicand,
532 IN INTN Multiplier,
533 OUT INTN *Result
534 )
535{
536 return SafeInt64ToIntn (MultS64x64 (Multiplicand, Multiplier), Result);
537}
UINT64 UINTN
INT64 INTN
INT64 EFIAPI MultS64x64(IN INT64 Multiplicand, IN INT64 Multiplier)
Definition: MultS64x64.c:27
#define NULL
Definition: Base.h:319
#define RETURN_BUFFER_TOO_SMALL
Definition: Base.h:1093
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define RETURN_INVALID_PARAMETER
Definition: Base.h:1076
RETURN_STATUS EFIAPI SafeInt64ToIntn(IN INT64 Operand, OUT INTN *Result)
Definition: SafeIntLib32.c:247
RETURN_STATUS EFIAPI SafeUint32ToIntn(IN UINT32 Operand, OUT INTN *Result)
Definition: SafeIntLib32.c:68
RETURN_STATUS EFIAPI SafeUintnAdd(IN UINTN Augend, IN UINTN Addend, OUT UINTN *Result)
Definition: SafeIntLib32.c:338
RETURN_STATUS EFIAPI SafeIntnToInt32(IN INTN Operand, OUT INT32 *Result)
Definition: SafeIntLib32.c:98
RETURN_STATUS EFIAPI SafeUintnMult(IN UINTN Multiplicand, IN UINTN Multiplier, OUT UINTN *Result)
Definition: SafeIntLib32.c:430
RETURN_STATUS EFIAPI SafeIntnToUint32(IN INTN Operand, OUT UINT32 *Result)
Definition: SafeIntLib32.c:133
RETURN_STATUS EFIAPI SafeUintnToUint32(IN UINTN Operand, OUT UINT32 *Result)
Definition: SafeIntLib32.c:177
RETURN_STATUS EFIAPI SafeIntnMult(IN INTN Multiplicand, IN INTN Multiplier, OUT INTN *Result)
Definition: SafeIntLib32.c:530
RETURN_STATUS EFIAPI SafeIntnSub(IN INTN Minuend, IN INTN Subtrahend, OUT INTN *Result)
Definition: SafeIntLib32.c:498
RETURN_STATUS EFIAPI SafeUintnToInt64(IN UINTN Operand, OUT INT64 *Result)
Definition: SafeIntLib32.c:212
RETURN_STATUS EFIAPI SafeInt32ToUintn(IN INT32 Operand, OUT UINTN *Result)
Definition: SafeIntLib32.c:38
RETURN_STATUS EFIAPI SafeIntnAdd(IN INTN Augend, IN INTN Addend, OUT INTN *Result)
Definition: SafeIntLib32.c:466
RETURN_STATUS EFIAPI SafeInt64ToUintn(IN INT64 Operand, OUT UINTN *Result)
Definition: SafeIntLib32.c:277
RETURN_STATUS EFIAPI SafeUint64ToUintn(IN UINT64 Operand, OUT UINTN *Result)
Definition: SafeIntLib32.c:307
RETURN_STATUS EFIAPI SafeUintnSub(IN UINTN Minuend, IN UINTN Subtrahend, OUT UINTN *Result)
Definition: SafeIntLib32.c:384
RETURN_STATUS EFIAPI SafeInt64ToInt32(IN INT64 Operand, OUT INT32 *Result)
Definition: SafeIntLib.c:2302
RETURN_STATUS EFIAPI SafeUint32ToInt32(IN UINT32 Operand, OUT INT32 *Result)
Definition: SafeIntLib.c:1422
RETURN_STATUS EFIAPI SafeInt32ToUint32(IN INT32 Operand, OUT UINT32 *Result)
Definition: SafeIntLib.c:1114
RETURN_STATUS EFIAPI SafeInt64ToUint32(IN INT64 Operand, OUT UINT32 *Result)
Definition: SafeIntLib.c:2346
RETURN_STATUS EFIAPI SafeUint64ToUint32(IN UINT64 Operand, OUT UINT32 *Result)
Definition: SafeIntLib.c:2698