[cover] Fix divide by zero
Divide by zero occurred when the maximum dictionary size was less than 2048.
Fixes #792.
Division by zero exception instead of ZSTD_error_dstSize_tooSmall in `COVER_buildDictionary` at https://github.com/facebook/zstd/blob/dev/lib/dictBuilder/cover.c#L611 in case of small maxdict param value provided
```
zstd --train sample.json --maxdict=1024
```
sample.json

```
['a': 'constant_field', 'b': '1615890720', 'c': 1068041704, 'd': 'sometimes constant field']['a': 'constant_field', 'b': '1987910979', 'c': 1136274312, 'd': 'sometimes constant field']['a': 'constant_field', 'b': '458354839', 'c': 752791499, 'd': 'sometimes constant field']['a': 'constant_field', 'b': '1345300048', 'c': 1808022441, 'd': 'sometimes constant field']['a': 'constant_field', 'b': '317792882', 'c': 1971021450, 'd': 'sometimes constant field']['a': 'constant_field', 'b': '1083291535', 'c': 365688543, 'd': 'sometimes constant field']['a': 'constant_field', 'b': '1505090195', 'c': 683584065, 'd': 'sometimes constant field']['a': 'constant_field', 'b': '1896415458', 'c': 941930511, 'd': 'sometimes constant field']['a': 'constant_field', 'b': '597682527', 'c': 1729893465, 'd': 'sometimes constant field']['a': 'constant_field', 'b': '416102126', 'c': 660877617, 'd': 'sometimes constant field']
```
output
```
ZDICT_optimizeTrainFromBuffer_cover:
kSteps 4
kStepSize 487
kIterations 5

Trying 5 different sets of parameters
#d 8
#k 50
COVER_buildDictionary: dictBufferCapacity 1024
COVER_buildDictionary: parameters.k 50
COVER_buildDictionary: epochs 20

                                                                      
statistics ... 
HUF_writeCTable error 
Failed to finalize dictionary
#k 537
COVER_buildDictionary: dictBufferCapacity 1024
COVER_buildDictionary: parameters.k 537
COVER_buildDictionary: epochs 1

                                                                      
statistics ... 
HUF_writeCTable error 
Failed to finalize dictionary
#k 1024
COVER_buildDictionary: dictBufferCapacity 1024
COVER_buildDictionary: parameters.k 1024
COVER_buildDictionary: epochs 1

                                                                      
statistics ... 
HUF_writeCTable error 
Failed to finalize dictionary
#k 1511
COVER_buildDictionary: dictBufferCapacity 1024
COVER_buildDictionary: parameters.k 1511
COVER_buildDictionary: epochs 0
```
Division by zero on dict training
diff --git a/lib/dictBuilder/cover.c b/lib/dictBuilder/cover.c
index 3d445ae8b81..cc4b1337609 100644
--- a/lib/dictBuilder/cover.c
+++ b/lib/dictBuilder/cover.c
@@ -479,11 +479,16 @@ static COVER_segment_t COVER_selectSegment(const COVER_ctx_t *ctx, U32 *freqs,
  * Check the validity of the parameters.
  * Returns non-zero if the parameters are valid and 0 otherwise.
  */
-static int COVER_checkParameters(ZDICT_cover_params_t parameters) {
+static int COVER_checkParameters(ZDICT_cover_params_t parameters,
+                                 size_t maxDictSize) {
   /* k and d are required parameters */
   if (parameters.d == 0 || parameters.k == 0) {
     return 0;
   }
+  /* k <= maxDictSize */
+  if (parameters.k > maxDictSize) {
+    return 0;
+  }
   /* d <= k */
   if (parameters.d > parameters.k) {
     return 0;
@@ -648,7 +653,7 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_cover(
   COVER_ctx_t ctx;
   COVER_map_t activeDmers;
   /* Checks */
-  if (!COVER_checkParameters(parameters)) {
+  if (!COVER_checkParameters(parameters, dictBufferCapacity)) {
     DISPLAYLEVEL(1, "Cover parameters incorrect\n");
     return ERROR(GENERIC);
   }
@@ -995,7 +1000,7 @@ ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
       data->parameters.d = d;
       data->parameters.steps = kSteps;
       /* Check the parameters */
-      if (!COVER_checkParameters(data->parameters)) {
+      if (!COVER_checkParameters(data->parameters, dictBufferCapacity)) {
         DISPLAYLEVEL(1, "Cover parameters incorrect\n");
         free(data);
         continue;

diff --git a/tests/playTests.sh b/tests/playTests.sh
index bc8584e7a9f..706cef2da69 100755
--- a/tests/playTests.sh
+++ b/tests/playTests.sh
@@ -291,8 +291,10 @@ $ECHO "- Create dictionary with wrong dictID parameter order (must fail)"
 $ZSTD --train *.c ../programs/*.c --dictID -o 1 tmpDict1 && die "wrong order : --dictID must be followed by argument "
 $ECHO "- Create dictionary with size limit"
 $ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict=4K -v
+$ECHO "- Create dictionary with small size limit"
+$ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict=1K -v
 $ECHO "- Create dictionary with wrong parameter order (must fail)"
-$ZSTD --train *.c ../programs/*.c -o tmpDict2 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
+$ZSTD --train *.c ../programs/*.c -o tmpDict3 --maxdict -v 4K && die "wrong order : --maxdict must be followed by argument "
 $ECHO "- Compress without dictID"
 $ZSTD -f tmp -D tmpDict1 --no-dictID
 $ZSTD -d tmp.zst -D tmpDict -fo result

{"testInvalid": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "testOrder": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"testInvalid": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "testOrder": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"passed_count": 2, "failed_count": 0, "skipped_count": 0, "passed_tests": ["testInvalid", "testOrder"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 0, "failed_count": 0, "skipped_count": 0, "passed_tests": [], "failed_tests": [], "skipped_tests": []}
{"passed_count": 2, "failed_count": 0, "skipped_count": 0, "passed_tests": ["testInvalid", "testOrder"], "failed_tests": [], "skipped_tests": []}