|
1 | 1 | /* ModelicaInternal.c - External functions for Modelica.Utilities |
2 | 2 |
|
3 | | - Copyright (C) 2002-2023, Modelica Association and contributors |
| 3 | + Copyright (C) 2002-2024, Modelica Association and contributors |
4 | 4 | All rights reserved. |
5 | 5 |
|
6 | 6 | Redistribution and use in source and binary forms, with or without |
|
30 | 30 | */ |
31 | 31 |
|
32 | 32 | /* Changelog: |
| 33 | + Jan. 15, 2024: by Thomas Beutlich |
| 34 | + Utilized ModelicaDuplicateString and |
| 35 | + ModelicaDuplicateStringWithErrorReturn (ticket #3686) |
| 36 | +
|
33 | 37 | Nov. 17, 2020: by Thomas Beutlich |
34 | 38 | Fixed reading files with Unix-style line endings on Windows |
35 | 39 | for ModelicaInternal_readLine/_readFile (ticket #3631) |
@@ -633,8 +637,7 @@ _Ret_z_ const char* ModelicaInternal_fullPathName(_In_z_ const char* name) { |
633 | 637 | if (tempName == NULL) { |
634 | 638 | goto FALLBACK_getcwd; |
635 | 639 | } |
636 | | - fullName = ModelicaAllocateString(strlen(tempName) + 1); |
637 | | - strcpy(fullName, tempName); |
| 640 | + fullName = ModelicaDuplicateString(tempName); |
638 | 641 | ModelicaConvertToUnixDirectorySeparator(fullName); |
639 | 642 | /* Retain trailing slash to match _fullpath behaviour */ |
640 | 643 | len = strlen(name); |
@@ -1073,8 +1076,7 @@ _Ret_z_ const char* ModelicaInternal_readLine(_In_z_ const char* fileName, |
1073 | 1076 | fclose(fp); |
1074 | 1077 | CloseCachedFile(fileName); |
1075 | 1078 | *endOfFile = 1; |
1076 | | - line = ModelicaAllocateString(0); |
1077 | | - line[0] = '\0'; |
| 1079 | + line = ModelicaDuplicateString(""); |
1078 | 1080 | return line; |
1079 | 1081 |
|
1080 | 1082 | Modelica_OOM_ERROR2: |
@@ -1150,18 +1152,16 @@ void ModelicaInternal_getenv(_In_z_ const char* name, int convertToSlash, |
1150 | 1152 | #endif |
1151 | 1153 |
|
1152 | 1154 | if (value == NULL) { |
1153 | | - result = ModelicaAllocateString(0); |
1154 | | - result[0] = '\0'; |
| 1155 | + result = ModelicaDuplicateString(""); |
1155 | 1156 | *exist = 0; |
1156 | 1157 | } |
1157 | 1158 | else { |
1158 | 1159 | #if defined(_MSC_VER) && _MSC_VER >= 1400 |
1159 | | - result = ModelicaAllocateStringWithErrorReturn(len); /* (len - 1) actually is sufficient */ |
| 1160 | + result = ModelicaDuplicateStringWithErrorReturn(value); |
1160 | 1161 | if (result) { |
1161 | 1162 | #else |
1162 | | - result = ModelicaAllocateString(strlen(value)); |
| 1163 | + result = ModelicaDuplicateString(value); |
1163 | 1164 | #endif |
1164 | | - strcpy(result, value); |
1165 | 1165 | if ( convertToSlash == 1 ) { |
1166 | 1166 | ModelicaConvertToUnixDirectorySeparator(result); |
1167 | 1167 | } |
|
0 commit comments