[Git][cmucl/cmucl][issue-120-software-type-in-c] Simplify code and use strdup to copy the strings

Raymond Toy (@rtoy) gitlab at common-lisp.net
Fri Sep 2 23:16:13 UTC 2022



Raymond Toy pushed to branch issue-120-software-type-in-c at cmucl / cmucl


Commits:
51d4f25b by Raymond Toy at 2022-09-02T16:00:01-07:00
Simplify code and use strdup to copy the strings

Reorder the code for os_software_version to keep all the
UNAME_RELEASE_AND_VERSION code together.  When
UNAME_RELEASE_AND_VERSION is not set, use strdup to copy the release.


In os_software_type, use strdup to copy the OS name, instead of
malloc+strcpy.

- - - - -


1 changed file:

- src/lisp/os-common.c


Changes:

=====================================
src/lisp/os-common.c
=====================================
@@ -740,19 +740,15 @@ os_software_version()
         int version_length;
 #if defined(UNAME_RELEASE_AND_VERSION)
         version_length = strlen(uts.release) + strlen(uts.version) + 2;
-#else
-        version_length = strlen(uts.version) + 1;
-#endif        
         version = malloc(version_length);
         if (version) {
-#if defined(UNAME_RELEASE_AND_VERSION)
             strcpy(version, uts.release);
             strcat(version, " ");
             strcat(version, uts.version);
+        }
 #else
-            strcpy(version, uts.version);
+        version = strdup(uts.version);
 #endif            
-        }
     }
 
     return version;
@@ -768,10 +764,7 @@ os_software_type()
     
     status = uname(&uts);
     if (status == 0) {
-        os_name = malloc(strlen(uts.sysname) + 1);
-        if (os_name) {
-            strcpy(os_name, uts.sysname);
-        }
+        os_name = strdup(uts.sysname);
     }
 
     return os_name;



View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/51d4f25b5c61298d978e7df6cfea382c7f161da7

-- 
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/51d4f25b5c61298d978e7df6cfea382c7f161da7
You're receiving this email because of your account on gitlab.common-lisp.net.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cmucl-cvs/attachments/20220902/41af1beb/attachment-0001.html>


More information about the cmucl-cvs mailing list