You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@celix.apache.org by GitBox <gi...@apache.org> on 2021/02/08 13:25:58 UTC

[GitHub] [celix] Oipo commented on a change in pull request #313: Feature/refactor c dep man service trackers

Oipo commented on a change in pull request #313:
URL: https://github.com/apache/celix/pull/313#discussion_r572007077



##########
File path: libs/utils/src/version_range.c
##########
@@ -182,61 +108,139 @@ celix_status_t versionRange_isHighInclusive(version_range_pt versionRange, bool
 
 
 celix_status_t versionRange_parse(const char * rangeStr, version_range_pt *range) {
-    celix_status_t status;
-    if (strchr(rangeStr, ',') != NULL) {
-            int vlowL = strcspn(rangeStr+1, ",");
-            char * vlow = (char *) malloc(sizeof(char) * (vlowL + 1));
-            if (!vlow) {
-                status = CELIX_ENOMEM;
-            } else {
-                int vhighL;
-                char * vhigh;
-                vlow = strncpy(vlow, rangeStr+1, vlowL);
-                vlow[vlowL] = '\0';
-                vhighL = strlen(rangeStr+1) - vlowL - 2;
-                vhigh = (char *) malloc(sizeof(char) * (vhighL+1));
-                if (!vhigh) {
-                    status = CELIX_ENOMEM;
-                } else {                    
-                    version_pt versionLow = NULL;
-                    int rangeL = strlen(rangeStr);
-                    char start = rangeStr[0];
-                    char end = rangeStr[rangeL-1];
-
-                    vhigh = strncpy(vhigh, rangeStr+vlowL+2, vhighL);
-                    vhigh[vhighL] = '\0';
-                    status = version_createVersionFromString(vlow, &versionLow);
-                    if (status == CELIX_SUCCESS) {
-                        version_pt versionHigh = NULL;
-                        status = version_createVersionFromString(vhigh, &versionHigh);
-                        if (status == CELIX_SUCCESS) {
-                            status = versionRange_createVersionRange(
-                                    versionLow,
-                                    start == '[',
-                                    versionHigh,
-                                    end ==']',
-                                    range
-                                );
-                        }
-                    }
-                    free(vhigh);
-                }
-                free(vlow);
+    *range = celix_versionRange_parse(rangeStr);
+    if (*range == NULL) {
+        return CELIX_ILLEGAL_ARGUMENT;
+    } else {
+        return CELIX_SUCCESS;
+    }
+}
 
+char* versionRange_createLDAPFilter(version_range_pt range, const char *serviceVersionAttributeName) {
+    return celix_versionRange_createLDAPFilter(range, serviceVersionAttributeName);
+}
+
+
+
+bool versionRange_createLDAPFilterInPlace(version_range_pt range, const char *serviceVersionAttributeName, char* buffer, size_t bufferLength) {
+    return celix_versionRange_createLDAPFilterInPlace(range, serviceVersionAttributeName, buffer, bufferLength);
+}
+
+celix_version_range_t* celix_versionRange_createVersionRange(celix_version_t* low, bool isLowInclusive, celix_version_t* high, bool isHighInclusive) {
+    assert(low != high);
+    celix_version_range_t* range = malloc(sizeof(*range));
+    range->low = low;
+    range->isLowInclusive = isLowInclusive;
+    range->high = high;
+    range->isHighInclusive = isHighInclusive;
+    return range;
+}
+
+
+celix_version_range_t* celix_versionRange_createInfiniteVersionRange() {
+    return celix_versionRange_createVersionRange(celix_version_createEmptyVersion(), true, NULL, true);
+}
+
+void celix_versionRange_destroy(celix_version_range_t* range) {
+    if (range->high != NULL) {
+        celix_version_destroy(range->high);
+    }
+    if (range->low != NULL) {
+        celix_version_destroy(range->low);
+    }
+    free(range);
+}
+
+
+bool celix_versionRange_isInRange(const celix_version_range_t* versionRange, const celix_version_t* version) {
+    bool inRange = false;
+    int high;
+    int low;

Review comment:
       Compiler warnings on these two uninitialized variables:
   ```
   /home/oipo-unencrypted/Programming/celix-apache/libs/utils/src/version_range.c:167:17: error: ‘low’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     167 |         inRange = (low >= 0);
         |         ~~~~~~~~^~~~~~~~~~~~
   /home/oipo-unencrypted/Programming/celix-apache/libs/utils/src/version_range.c:157:9: error: ‘high’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     157 |     int high;
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org