/src/liblnk/libcsplit/libcsplit_narrow_split_string.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Split narrow string functions  | 
3  |  |  *  | 
4  |  |  * Copyright (C) 2008-2024, Joachim Metz <joachim.metz@gmail.com>  | 
5  |  |  *  | 
6  |  |  * Refer to AUTHORS for acknowledgements.  | 
7  |  |  *  | 
8  |  |  * This program is free software: you can redistribute it and/or modify  | 
9  |  |  * it under the terms of the GNU Lesser General Public License as published by  | 
10  |  |  * the Free Software Foundation, either version 3 of the License, or  | 
11  |  |  * (at your option) any later version.  | 
12  |  |  *  | 
13  |  |  * This program is distributed in the hope that it will be useful,  | 
14  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
15  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  | 
16  |  |  * GNU General Public License for more details.  | 
17  |  |  *  | 
18  |  |  * You should have received a copy of the GNU Lesser General Public License  | 
19  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>.  | 
20  |  |  */  | 
21  |  |  | 
22  |  | #include <common.h>  | 
23  |  | #include <memory.h>  | 
24  |  | #include <narrow_string.h>  | 
25  |  | #include <types.h>  | 
26  |  |  | 
27  |  | #include "libcsplit_libcerror.h"  | 
28  |  | #include "libcsplit_narrow_split_string.h"  | 
29  |  | #include "libcsplit_types.h"  | 
30  |  |  | 
31  |  | /* Creates a split string  | 
32  |  |  * Make sure the value split_string is referencing, is set to NULL  | 
33  |  |  * Returns 1 if successful or -1 on error  | 
34  |  |  */  | 
35  |  | int libcsplit_narrow_split_string_initialize(  | 
36  |  |      libcsplit_narrow_split_string_t **split_string,  | 
37  |  |      const char *string,  | 
38  |  |      size_t string_size,  | 
39  |  |      int number_of_segments,  | 
40  |  |      libcerror_error_t **error )  | 
41  | 387k  | { | 
42  | 387k  |   libcsplit_internal_narrow_split_string_t *internal_split_string = NULL;  | 
43  | 387k  |   static char *function                                           = "libcsplit_narrow_split_string_initialize";  | 
44  |  |  | 
45  | 387k  |   if( split_string == NULL )  | 
46  | 0  |   { | 
47  | 0  |     libcerror_error_set(  | 
48  | 0  |      error,  | 
49  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
50  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
51  | 0  |      "%s: invalid split string.",  | 
52  | 0  |      function );  | 
53  |  | 
  | 
54  | 0  |     return( -1 );  | 
55  | 0  |   }  | 
56  | 387k  |   if( *split_string != NULL )  | 
57  | 0  |   { | 
58  | 0  |     libcerror_error_set(  | 
59  | 0  |      error,  | 
60  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
61  | 0  |      LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,  | 
62  | 0  |      "%s: invalid split string value already set.",  | 
63  | 0  |      function );  | 
64  |  | 
  | 
65  | 0  |     return( -1 );  | 
66  | 0  |   }  | 
67  | 387k  |   if( number_of_segments < 0 )  | 
68  | 0  |   { | 
69  | 0  |     libcerror_error_set(  | 
70  | 0  |      error,  | 
71  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
72  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO,  | 
73  | 0  |      "%s: invalid number of segments less than zero.",  | 
74  | 0  |      function );  | 
75  |  | 
  | 
76  | 0  |     return( -1 );  | 
77  | 0  |   }  | 
78  | 387k  |   internal_split_string = memory_allocate_structure(  | 
79  | 387k  |                libcsplit_internal_narrow_split_string_t );  | 
80  |  |  | 
81  | 387k  |   if( internal_split_string == NULL )  | 
82  | 0  |   { | 
83  | 0  |     libcerror_error_set(  | 
84  | 0  |      error,  | 
85  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
86  | 0  |      LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
87  | 0  |      "%s: unable to create split string.",  | 
88  | 0  |      function );  | 
89  |  | 
  | 
90  | 0  |     goto on_error;  | 
91  | 0  |   }  | 
92  | 387k  |   if( memory_set(  | 
93  | 387k  |        internal_split_string,  | 
94  | 387k  |        0,  | 
95  | 387k  |        sizeof( libcsplit_internal_narrow_split_string_t ) ) == NULL )  | 
96  | 0  |   { | 
97  | 0  |     libcerror_error_set(  | 
98  | 0  |      error,  | 
99  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
100  | 0  |      LIBCERROR_MEMORY_ERROR_SET_FAILED,  | 
101  | 0  |      "%s: unable to clear split string.",  | 
102  | 0  |      function );  | 
103  |  | 
  | 
104  | 0  |     memory_free(  | 
105  | 0  |      internal_split_string );  | 
106  |  | 
  | 
107  | 0  |     return( -1 );  | 
108  | 0  |   }  | 
109  | 387k  |   if( ( string != NULL )  | 
110  | 387k  |    && ( string_size > 0 ) )  | 
111  | 387k  |   { | 
112  | 387k  |     internal_split_string->string = narrow_string_allocate(  | 
113  | 387k  |                                      string_size );  | 
114  |  |  | 
115  | 387k  |     if( internal_split_string->string == NULL )  | 
116  | 0  |     { | 
117  | 0  |       libcerror_error_set(  | 
118  | 0  |        error,  | 
119  | 0  |        LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
120  | 0  |        LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
121  | 0  |        "%s: unable to create string.",  | 
122  | 0  |        function );  | 
123  |  | 
  | 
124  | 0  |       goto on_error;  | 
125  | 0  |     }  | 
126  | 387k  |     if( memory_copy(  | 
127  | 387k  |          internal_split_string->string,  | 
128  | 387k  |          string,  | 
129  | 387k  |          sizeof( char ) * ( string_size - 1 ) ) == NULL )  | 
130  | 0  |     { | 
131  | 0  |       libcerror_error_set(  | 
132  | 0  |        error,  | 
133  | 0  |        LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
134  | 0  |        LIBCERROR_MEMORY_ERROR_SET_FAILED,  | 
135  | 0  |        "%s: unable to copy string.",  | 
136  | 0  |        function );  | 
137  |  | 
  | 
138  | 0  |       goto on_error;  | 
139  | 0  |     }  | 
140  | 387k  |     internal_split_string->string[ string_size - 1 ] = 0;  | 
141  | 387k  |     internal_split_string->string_size               = string_size;  | 
142  | 387k  |   }  | 
143  | 387k  |   if( number_of_segments > 0 )  | 
144  | 387k  |   { | 
145  | 387k  |     internal_split_string->segments = (char **) memory_allocate(  | 
146  | 387k  |                                                  sizeof( char * ) * number_of_segments );  | 
147  |  |  | 
148  | 387k  |     if( internal_split_string->segments == NULL )  | 
149  | 0  |     { | 
150  | 0  |       libcerror_error_set(  | 
151  | 0  |        error,  | 
152  | 0  |        LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
153  | 0  |        LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
154  | 0  |        "%s: unable to create segments.",  | 
155  | 0  |        function );  | 
156  |  | 
  | 
157  | 0  |       goto on_error;  | 
158  | 0  |     }  | 
159  | 387k  |     if( memory_set(  | 
160  | 387k  |          internal_split_string->segments,  | 
161  | 387k  |          0,  | 
162  | 387k  |          sizeof( char * ) * number_of_segments ) == NULL )  | 
163  | 0  |     { | 
164  | 0  |       libcerror_error_set(  | 
165  | 0  |        error,  | 
166  | 0  |        LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
167  | 0  |        LIBCERROR_MEMORY_ERROR_SET_FAILED,  | 
168  | 0  |        "%s: unable to clear segments.",  | 
169  | 0  |        function );  | 
170  |  | 
  | 
171  | 0  |       goto on_error;  | 
172  | 0  |     }  | 
173  | 387k  |     internal_split_string->segment_sizes = (size_t *) memory_allocate(  | 
174  | 387k  |                                                        sizeof( size_t ) * number_of_segments );  | 
175  |  |  | 
176  | 387k  |     if( internal_split_string->segment_sizes == NULL )  | 
177  | 0  |     { | 
178  | 0  |       libcerror_error_set(  | 
179  | 0  |        error,  | 
180  | 0  |        LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
181  | 0  |        LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
182  | 0  |        "%s: unable to create segment sizes.",  | 
183  | 0  |        function );  | 
184  |  | 
  | 
185  | 0  |       goto on_error;  | 
186  | 0  |     }  | 
187  | 387k  |     if( memory_set(  | 
188  | 387k  |          internal_split_string->segment_sizes,  | 
189  | 387k  |          0,  | 
190  | 387k  |          sizeof( size_t ) * number_of_segments ) == NULL )  | 
191  | 0  |     { | 
192  | 0  |       libcerror_error_set(  | 
193  | 0  |        error,  | 
194  | 0  |        LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
195  | 0  |        LIBCERROR_MEMORY_ERROR_SET_FAILED,  | 
196  | 0  |        "%s: unable to clear segment sizes.",  | 
197  | 0  |        function );  | 
198  |  | 
  | 
199  | 0  |       goto on_error;  | 
200  | 0  |     }  | 
201  | 387k  |   }  | 
202  | 387k  |   internal_split_string->number_of_segments = number_of_segments;  | 
203  |  |  | 
204  | 387k  |   *split_string = (libcsplit_narrow_split_string_t *) internal_split_string;  | 
205  |  |  | 
206  | 387k  |   return( 1 );  | 
207  |  |  | 
208  | 0  | on_error:  | 
209  | 0  |   if( internal_split_string != NULL )  | 
210  | 0  |   { | 
211  | 0  |     if( internal_split_string->segment_sizes != NULL )  | 
212  | 0  |     { | 
213  | 0  |       memory_free(  | 
214  | 0  |        internal_split_string->segment_sizes );  | 
215  | 0  |     }  | 
216  | 0  |     if( internal_split_string->segments != NULL )  | 
217  | 0  |     { | 
218  | 0  |       memory_free(  | 
219  | 0  |        internal_split_string->segments );  | 
220  | 0  |     }  | 
221  | 0  |     if( internal_split_string->string != NULL )  | 
222  | 0  |     { | 
223  | 0  |       memory_free(  | 
224  | 0  |        internal_split_string->string );  | 
225  | 0  |     }  | 
226  | 0  |     memory_free(  | 
227  | 0  |      internal_split_string );  | 
228  | 0  |   }  | 
229  | 0  |   return( -1 );  | 
230  | 387k  | }  | 
231  |  |  | 
232  |  | /* Frees a split string  | 
233  |  |  * Returns 1 if successful or -1 on error  | 
234  |  |  */  | 
235  |  | int libcsplit_narrow_split_string_free(  | 
236  |  |      libcsplit_narrow_split_string_t **split_string,  | 
237  |  |      libcerror_error_t **error )  | 
238  | 387k  | { | 
239  | 387k  |   libcsplit_internal_narrow_split_string_t *internal_split_string = NULL;  | 
240  | 387k  |   static char *function                                           = "libcsplit_narrow_split_string_free";  | 
241  |  |  | 
242  | 387k  |   if( split_string == NULL )  | 
243  | 0  |   { | 
244  | 0  |     libcerror_error_set(  | 
245  | 0  |      error,  | 
246  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
247  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
248  | 0  |      "%s: invalid split string.",  | 
249  | 0  |      function );  | 
250  |  | 
  | 
251  | 0  |     return( -1 );  | 
252  | 0  |   }  | 
253  | 387k  |   if( *split_string != NULL )  | 
254  | 387k  |   { | 
255  | 387k  |     internal_split_string = (libcsplit_internal_narrow_split_string_t *) *split_string;  | 
256  | 387k  |     *split_string         = NULL;  | 
257  |  |  | 
258  | 387k  |     if( internal_split_string->string != NULL )  | 
259  | 387k  |     { | 
260  | 387k  |       memory_free(  | 
261  | 387k  |        internal_split_string->string );  | 
262  | 387k  |     }  | 
263  | 387k  |     if( internal_split_string->segments != NULL )  | 
264  | 387k  |     { | 
265  | 387k  |       memory_free(  | 
266  | 387k  |        internal_split_string->segments );  | 
267  | 387k  |     }  | 
268  | 387k  |     if( internal_split_string->segment_sizes != NULL )  | 
269  | 387k  |     { | 
270  | 387k  |       memory_free(  | 
271  | 387k  |        internal_split_string->segment_sizes );  | 
272  | 387k  |     }  | 
273  | 387k  |     memory_free(  | 
274  | 387k  |      internal_split_string );  | 
275  | 387k  |   }  | 
276  | 387k  |   return( 1 );  | 
277  | 387k  | }  | 
278  |  |  | 
279  |  | /* Retrieves the string  | 
280  |  |  * Returns 1 if successful or -1 on error  | 
281  |  |  */  | 
282  |  | int libcsplit_narrow_split_string_get_string(  | 
283  |  |      libcsplit_narrow_split_string_t *split_string,  | 
284  |  |      char **string,  | 
285  |  |      size_t *string_size,  | 
286  |  |      libcerror_error_t **error )  | 
287  | 387k  | { | 
288  | 387k  |   libcsplit_internal_narrow_split_string_t *internal_split_string = NULL;  | 
289  | 387k  |   static char *function                                           = "libcsplit_narrow_split_string_get_string";  | 
290  |  |  | 
291  | 387k  |   if( split_string == NULL )  | 
292  | 0  |   { | 
293  | 0  |     libcerror_error_set(  | 
294  | 0  |      error,  | 
295  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
296  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
297  | 0  |      "%s: invalid split string.",  | 
298  | 0  |      function );  | 
299  |  | 
  | 
300  | 0  |     return( -1 );  | 
301  | 0  |   }  | 
302  | 387k  |   internal_split_string = (libcsplit_internal_narrow_split_string_t *) split_string;  | 
303  |  |  | 
304  | 387k  |   if( string == NULL )  | 
305  | 0  |   { | 
306  | 0  |     libcerror_error_set(  | 
307  | 0  |      error,  | 
308  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
309  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
310  | 0  |      "%s: invalid string.",  | 
311  | 0  |      function );  | 
312  |  | 
  | 
313  | 0  |     return( -1 );  | 
314  | 0  |   }  | 
315  | 387k  |   if( string_size == NULL )  | 
316  | 0  |   { | 
317  | 0  |     libcerror_error_set(  | 
318  | 0  |      error,  | 
319  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
320  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
321  | 0  |      "%s: invalid string size.",  | 
322  | 0  |      function );  | 
323  |  | 
  | 
324  | 0  |     return( -1 );  | 
325  | 0  |   }  | 
326  | 387k  |   *string      = internal_split_string->string;  | 
327  | 387k  |   *string_size = internal_split_string->string_size;  | 
328  |  |  | 
329  | 387k  |   return( 1 );  | 
330  | 387k  | }  | 
331  |  |  | 
332  |  | /* Retrieves the number of segments  | 
333  |  |  * Returns 1 if successful or -1 on error  | 
334  |  |  */  | 
335  |  | int libcsplit_narrow_split_string_get_number_of_segments(  | 
336  |  |      libcsplit_narrow_split_string_t *split_string,  | 
337  |  |      int *number_of_segments,  | 
338  |  |      libcerror_error_t **error )  | 
339  | 387k  | { | 
340  | 387k  |   libcsplit_internal_narrow_split_string_t *internal_split_string = NULL;  | 
341  | 387k  |   static char *function                                           = "libcsplit_narrow_split_string_get_number_of_segments";  | 
342  |  |  | 
343  | 387k  |   if( split_string == NULL )  | 
344  | 23  |   { | 
345  | 23  |     libcerror_error_set(  | 
346  | 23  |      error,  | 
347  | 23  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
348  | 23  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
349  | 23  |      "%s: invalid split string.",  | 
350  | 23  |      function );  | 
351  |  |  | 
352  | 23  |     return( -1 );  | 
353  | 23  |   }  | 
354  | 387k  |   internal_split_string = (libcsplit_internal_narrow_split_string_t *) split_string;  | 
355  |  |  | 
356  | 387k  |   if( number_of_segments == NULL )  | 
357  | 0  |   { | 
358  | 0  |     libcerror_error_set(  | 
359  | 0  |      error,  | 
360  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
361  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
362  | 0  |      "%s: invalid number of segments.",  | 
363  | 0  |      function );  | 
364  |  | 
  | 
365  | 0  |     return( -1 );  | 
366  | 0  |   }  | 
367  | 387k  |   *number_of_segments = internal_split_string->number_of_segments;  | 
368  |  |  | 
369  | 387k  |   return( 1 );  | 
370  | 387k  | }  | 
371  |  |  | 
372  |  | /* Retrieves a specific segment  | 
373  |  |  * Returns 1 if successful or -1 on error  | 
374  |  |  */  | 
375  |  | int libcsplit_narrow_split_string_get_segment_by_index(  | 
376  |  |      libcsplit_narrow_split_string_t *split_string,  | 
377  |  |      int segment_index,  | 
378  |  |      char **string_segment,  | 
379  |  |      size_t *string_segment_size,  | 
380  |  |      libcerror_error_t **error )  | 
381  | 48.6M  | { | 
382  | 48.6M  |   libcsplit_internal_narrow_split_string_t *internal_split_string = NULL;  | 
383  | 48.6M  |   static char *function                                           = "libcsplit_narrow_split_string_get_segment_by_index";  | 
384  |  |  | 
385  | 48.6M  |   if( split_string == NULL )  | 
386  | 0  |   { | 
387  | 0  |     libcerror_error_set(  | 
388  | 0  |      error,  | 
389  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
390  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
391  | 0  |      "%s: invalid split string.",  | 
392  | 0  |      function );  | 
393  |  | 
  | 
394  | 0  |     return( -1 );  | 
395  | 0  |   }  | 
396  | 48.6M  |   internal_split_string = (libcsplit_internal_narrow_split_string_t *) split_string;  | 
397  |  |  | 
398  | 48.6M  |   if( ( segment_index < 0 )  | 
399  | 48.6M  |    || ( segment_index >= internal_split_string->number_of_segments ) )  | 
400  | 0  |   { | 
401  | 0  |     libcerror_error_set(  | 
402  | 0  |      error,  | 
403  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
404  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,  | 
405  | 0  |      "%s: invalid segment index value out of bounds.",  | 
406  | 0  |      function );  | 
407  |  | 
  | 
408  | 0  |     return( -1 );  | 
409  | 0  |   }  | 
410  | 48.6M  |   if( string_segment == NULL )  | 
411  | 0  |   { | 
412  | 0  |     libcerror_error_set(  | 
413  | 0  |      error,  | 
414  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
415  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
416  | 0  |      "%s: invalid string segment.",  | 
417  | 0  |      function );  | 
418  |  | 
  | 
419  | 0  |     return( -1 );  | 
420  | 0  |   }  | 
421  | 48.6M  |   if( string_segment_size == NULL )  | 
422  | 0  |   { | 
423  | 0  |     libcerror_error_set(  | 
424  | 0  |      error,  | 
425  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
426  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
427  | 0  |      "%s: invalid string segment size.",  | 
428  | 0  |      function );  | 
429  |  | 
  | 
430  | 0  |     return( -1 );  | 
431  | 0  |   }  | 
432  | 48.6M  |   *string_segment      = internal_split_string->segments[ segment_index ];  | 
433  | 48.6M  |   *string_segment_size = internal_split_string->segment_sizes[ segment_index ];  | 
434  |  |  | 
435  | 48.6M  |   return( 1 );  | 
436  | 48.6M  | }  | 
437  |  |  | 
438  |  | /* Sets a specific segment  | 
439  |  |  * Returns 1 if successful or -1 on error  | 
440  |  |  */  | 
441  |  | int libcsplit_narrow_split_string_set_segment_by_index(  | 
442  |  |      libcsplit_narrow_split_string_t *split_string,  | 
443  |  |      int segment_index,  | 
444  |  |      char *string_segment,  | 
445  |  |      size_t string_segment_size,  | 
446  |  |      libcerror_error_t **error )  | 
447  | 49.7M  | { | 
448  | 49.7M  |   libcsplit_internal_narrow_split_string_t *internal_split_string = NULL;  | 
449  | 49.7M  |   static char *function                                           = "libcsplit_narrow_split_string_set_segment_by_index";  | 
450  | 49.7M  |   size_t string_segment_offset                                    = 0;  | 
451  |  |  | 
452  | 49.7M  |   if( split_string == NULL )  | 
453  | 0  |   { | 
454  | 0  |     libcerror_error_set(  | 
455  | 0  |      error,  | 
456  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
457  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
458  | 0  |      "%s: invalid split string.",  | 
459  | 0  |      function );  | 
460  |  | 
  | 
461  | 0  |     return( -1 );  | 
462  | 0  |   }  | 
463  | 49.7M  |   internal_split_string = (libcsplit_internal_narrow_split_string_t *) split_string;  | 
464  |  |  | 
465  | 49.7M  |   if( ( segment_index < 0 )  | 
466  | 49.7M  |    || ( segment_index >= internal_split_string->number_of_segments ) )  | 
467  | 0  |   { | 
468  | 0  |     libcerror_error_set(  | 
469  | 0  |      error,  | 
470  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
471  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,  | 
472  | 0  |      "%s: invalid segment index value out of bounds.",  | 
473  | 0  |      function );  | 
474  |  | 
  | 
475  | 0  |     return( -1 );  | 
476  | 0  |   }  | 
477  | 49.7M  |   if( string_segment_size > (size_t) SSIZE_MAX )  | 
478  | 0  |   { | 
479  | 0  |     libcerror_error_set(  | 
480  | 0  |      error,  | 
481  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
482  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,  | 
483  | 0  |      "%s: invalid string segment size value exceeds maximum.",  | 
484  | 0  |      function );  | 
485  |  | 
  | 
486  | 0  |     return( -1 );  | 
487  | 0  |   }  | 
488  | 49.7M  |   if( string_segment == NULL )  | 
489  | 0  |   { | 
490  | 0  |     if( string_segment_size != 0 )  | 
491  | 0  |     { | 
492  | 0  |       libcerror_error_set(  | 
493  | 0  |        error,  | 
494  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
495  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,  | 
496  | 0  |        "%s: invalid string segment size value out of bounds.",  | 
497  | 0  |        function );  | 
498  |  | 
  | 
499  | 0  |       return( -1 );  | 
500  | 0  |     }  | 
501  | 0  |   }  | 
502  | 49.7M  |   else  | 
503  | 49.7M  |   { | 
504  | 49.7M  |     if( string_segment < internal_split_string->string )  | 
505  | 0  |     { | 
506  | 0  |       libcerror_error_set(  | 
507  | 0  |        error,  | 
508  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
509  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,  | 
510  | 0  |        "%s: invalid string segment value out of bounds.",  | 
511  | 0  |        function );  | 
512  |  | 
  | 
513  | 0  |       return( -1 );  | 
514  | 0  |     }  | 
515  | 49.7M  |     string_segment_offset = (size_t) ( string_segment - internal_split_string->string );  | 
516  |  |  | 
517  | 49.7M  |     if( string_segment_offset >= internal_split_string->string_size )  | 
518  | 0  |     { | 
519  | 0  |       libcerror_error_set(  | 
520  | 0  |        error,  | 
521  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
522  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,  | 
523  | 0  |        "%s: invalid string segment value out of bounds.",  | 
524  | 0  |        function );  | 
525  |  | 
  | 
526  | 0  |       return( -1 );  | 
527  | 0  |     }  | 
528  | 49.7M  |     string_segment_offset += string_segment_size;  | 
529  |  |  | 
530  | 49.7M  |     if( string_segment_offset > internal_split_string->string_size )  | 
531  | 0  |     { | 
532  | 0  |       libcerror_error_set(  | 
533  | 0  |        error,  | 
534  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
535  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,  | 
536  | 0  |        "%s: invalid string segment value out of bounds.",  | 
537  | 0  |        function );  | 
538  |  | 
  | 
539  | 0  |       return( -1 );  | 
540  | 0  |     }  | 
541  | 49.7M  |   }  | 
542  | 49.7M  |   internal_split_string->segments[ segment_index ]      = string_segment;  | 
543  | 49.7M  |   internal_split_string->segment_sizes[ segment_index ] = string_segment_size;  | 
544  |  |  | 
545  | 49.7M  |   return( 1 );  | 
546  | 49.7M  | }  | 
547  |  |  |