1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Utility (Utility)                                                   */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_utility.h"
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_utility_string_length_check                     PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function traverses the string and returns the string length,   */
43 /*    if the string is invalid or the string length is bigger than max    */
44 /*    string length, returns error.                                       */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    input_string                          Pointer to input string       */
49 /*    string_length                         Pointer to string length      */
50 /*    max_string_length                     Max string length             */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    None                                                                */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    GUIX Internal Code                                                  */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
69 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_gx_utility_string_length_check(GX_CONST GX_CHAR * input_string,UINT * string_length,UINT max_string_length)73 UINT  _gx_utility_string_length_check(GX_CONST GX_CHAR *input_string, UINT *string_length, UINT max_string_length)
74 {
75 UINT i;
76 
77     /* Check for invalid input pointers.  */
78     if (input_string == GX_NULL)
79     {
80         return(GX_PTR_ERROR);
81     }
82 
83     /* Traverse the string.  */
84     for (i = 0; input_string[i]; i++)
85     {
86 
87         /* Check if the string length is bigger than the max string length.  */
88         if (i >= max_string_length)
89         {
90             return(GX_INVALID_STRING_LENGTH);
91         }
92     }
93 
94     /* Return the string length if string_length is not NULL.
95        String_length being NULL indicates the caller needs to check for string
96        length within the max_string_length. */
97     if (string_length)
98     {
99         *string_length = i;
100     }
101 
102     return(GX_SUCCESS);
103 }
104 
105