handle edge-cases in cow reference counting
@@ -14,6 +14,11 @@ uint16_t keyNameRefInc (struct _KeyName * keyname)
return UINT16_MAX;
}
+ if (keyname->refs == UINT16_MAX - 1)
+ {
+ return UINT16_MAX;
+ }
+
keyname->refs++;
return keyname->refs;
}
@@ -25,6 +30,11 @@ uint16_t keyNameRefDec (struct _KeyName * keyname)
return UINT16_MAX;
}
+ if (keyname->refs == 0)
+ {
+ return 0;
+ }
+
keyname->refs--;
return keyname->refs;
}
@@ -84,6 +94,11 @@ uint16_t keyDataRefInc (struct _KeyData * keydata)
return UINT16_MAX;
}
+ if (keydata->refs == UINT16_MAX - 1)
+ {
+ return UINT16_MAX;
+ }
+
keydata->refs++;
return keydata->refs;
}
@@ -95,6 +110,11 @@ uint16_t keyDataRefDec (struct _KeyData * keydata)
return UINT16_MAX;
}
+ if (keydata->refs == 0)
+ {
+ return 0;
+ }
+
keydata->refs--;
return keydata->refs;
}
@@ -147,6 +167,11 @@ uint16_t keySetDataRefInc (struct _KeySetData * keysetdata)
return UINT16_MAX;
}
+ if (keysetdata->refs == UINT16_MAX - 1)
+ {
+ return UINT16_MAX;
+ }
+
keysetdata->refs++;
return keysetdata->refs;
}
@@ -158,6 +183,11 @@ uint16_t keySetDataRefDec (struct _KeySetData * keysetdata)
return UINT16_MAX;
}
+ if (keysetdata->refs == 0)
+ {
+ return 0;
+ }
+
keysetdata->refs--;
return keysetdata->refs;
}
