1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Utility */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#define UX_SOURCE_CODE |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
/**************************************************************************/ |
32 |
|
|
/* */ |
33 |
|
|
/* FUNCTION RELEASE */ |
34 |
|
|
/* */ |
35 |
|
|
/* _ux_utility_string_length_check PORTABLE C */ |
36 |
|
|
/* 6.1.12 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function checks if a NULL-terminated C string reaches its end */ |
44 |
|
|
/* before specified length exceeds. */ |
45 |
|
|
/* */ |
46 |
|
|
/* On success the actual length of C string is written back to UINT */ |
47 |
|
|
/* variable pointed by string_length_ptr (if not NULL). */ |
48 |
|
|
/* Otherwise the variable keeps untouched. */ |
49 |
|
|
/* */ |
50 |
|
|
/* Note NULL terminator is not counted in string length */ |
51 |
|
|
/* (same as C strlen). */ |
52 |
|
|
/* */ |
53 |
|
|
/* INPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* string Pointer to string */ |
56 |
|
|
/* string_length_ptr Pointer to UINT to receive */ |
57 |
|
|
/* the string length */ |
58 |
|
|
/* max_string_length Max string length */ |
59 |
|
|
/* */ |
60 |
|
|
/* OUTPUT */ |
61 |
|
|
/* */ |
62 |
|
|
/* returns success if the string length was less than the max length, */ |
63 |
|
|
/* else it returns error */ |
64 |
|
|
/* */ |
65 |
|
|
/* CALLS */ |
66 |
|
|
/* */ |
67 |
|
|
/* None */ |
68 |
|
|
/* */ |
69 |
|
|
/* CALLED BY */ |
70 |
|
|
/* */ |
71 |
|
|
/* USBX Components */ |
72 |
|
|
/* */ |
73 |
|
|
/**************************************************************************/ |
74 |
|
18016 |
UINT _ux_utility_string_length_check(UCHAR *string, UINT *string_length_ptr, UINT max_string_length) |
75 |
|
|
{ |
76 |
|
|
|
77 |
|
|
UINT string_length; |
78 |
|
|
|
79 |
|
|
|
80 |
✓✓ |
18016 |
if (string == UX_NULL) |
81 |
|
1 |
return(UX_ERROR); |
82 |
|
|
|
83 |
|
18015 |
string_length = 0; |
84 |
|
|
|
85 |
|
|
while (1) |
86 |
|
|
{ |
87 |
|
|
|
88 |
✓✓ |
330936 |
if (string[string_length] == '\0') |
89 |
|
18007 |
break; |
90 |
|
|
|
91 |
|
312929 |
string_length++; |
92 |
✓✓ |
312929 |
if (string_length > max_string_length) |
93 |
|
|
{ |
94 |
|
|
|
95 |
|
|
/* Error trap. */ |
96 |
|
8 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_UTILITY, UX_ERROR); |
97 |
|
|
|
98 |
|
8 |
return(UX_ERROR); |
99 |
|
|
} |
100 |
|
|
} |
101 |
|
|
|
102 |
✓✓ |
18007 |
if (string_length_ptr) |
103 |
|
18006 |
*string_length_ptr = string_length; |
104 |
|
|
|
105 |
|
18007 |
return(UX_SUCCESS); |
106 |
|
|
} |
107 |
|
|
|