Fossil SCM
Fix memcpy() compiler warnings.
Commit
7ae4b1a719c4a175a47e135dc00c9a84065f36640e637a74abf60b0378f6f283
Parent
f7c41be825ba568…
1 file changed
+20
-12
M
src/th.c
+20
-12
| --- src/th.c | ||
| +++ src/th.c | ||
| @@ -202,10 +202,18 @@ | ||
| 202 | 202 | }; |
| 203 | 203 | typedef struct Buffer Buffer; |
| 204 | 204 | static int thBufferWrite(Th_Interp *interp, Buffer *, const char *, int); |
| 205 | 205 | static void thBufferInit(Buffer *); |
| 206 | 206 | static void thBufferFree(Th_Interp *interp, Buffer *); |
| 207 | + | |
| 208 | +/* | |
| 209 | +** This version of memcpy() allows the first are second argument to | |
| 210 | +** be NULL as long as the number of bytes to copy is zero. | |
| 211 | +*/ | |
| 212 | +static void *th_memcpy(void *dest, const void *src, size_t n){ | |
| 213 | + return n>0 ? memcpy(dest,src,n) : dest; | |
| 214 | +} | |
| 207 | 215 | |
| 208 | 216 | /* |
| 209 | 217 | ** Append nAdd bytes of content copied from zAdd to the end of buffer |
| 210 | 218 | ** pBuffer. If there is not enough space currently allocated, resize |
| 211 | 219 | ** the allocation to make space. |
| @@ -227,17 +235,17 @@ | ||
| 227 | 235 | char *zNew; |
| 228 | 236 | int nNew; |
| 229 | 237 | |
| 230 | 238 | nNew = nReq*2; |
| 231 | 239 | zNew = (char *)Th_Malloc(interp, nNew); |
| 232 | - memcpy(zNew, pBuffer->zBuf, pBuffer->nBuf); | |
| 240 | + th_memcpy(zNew, pBuffer->zBuf, pBuffer->nBuf); | |
| 233 | 241 | Th_Free(interp, pBuffer->zBuf); |
| 234 | 242 | pBuffer->nBufAlloc = nNew; |
| 235 | 243 | pBuffer->zBuf = zNew; |
| 236 | 244 | } |
| 237 | 245 | |
| 238 | - memcpy(&pBuffer->zBuf[pBuffer->nBuf], zAdd, nAdd); | |
| 246 | + th_memcpy(&pBuffer->zBuf[pBuffer->nBuf], zAdd, nAdd); | |
| 239 | 247 | pBuffer->nBuf += nAdd; |
| 240 | 248 | pBuffer->zBuf[pBuffer->nBuf] = '\0'; |
| 241 | 249 | |
| 242 | 250 | return TH_OK; |
| 243 | 251 | } |
| @@ -841,12 +849,12 @@ | ||
| 841 | 849 | sizeof(int) * nCount + /* anElem */ |
| 842 | 850 | strbuf.nBuf /* space for list element strings */ |
| 843 | 851 | ); |
| 844 | 852 | anElem = (int *)&azElem[nCount]; |
| 845 | 853 | zElem = (char *)&anElem[nCount]; |
| 846 | - memcpy(anElem, lenbuf.zBuf, lenbuf.nBuf); | |
| 847 | - memcpy(zElem, strbuf.zBuf, strbuf.nBuf); | |
| 854 | + th_memcpy(anElem, lenbuf.zBuf, lenbuf.nBuf); | |
| 855 | + th_memcpy(zElem, strbuf.zBuf, strbuf.nBuf); | |
| 848 | 856 | for(i=0; i<nCount;i++){ |
| 849 | 857 | azElem[i] = zElem; |
| 850 | 858 | zElem += (anElem[i] + 1); |
| 851 | 859 | } |
| 852 | 860 | *pazElem = azElem; |
| @@ -1293,11 +1301,11 @@ | ||
| 1293 | 1301 | } |
| 1294 | 1302 | |
| 1295 | 1303 | assert(zValue || nValue==0); |
| 1296 | 1304 | pValue->zData = Th_Malloc(interp, nValue+1); |
| 1297 | 1305 | pValue->zData[nValue] = '\0'; |
| 1298 | - memcpy(pValue->zData, zValue, nValue); | |
| 1306 | + th_memcpy(pValue->zData, zValue, nValue); | |
| 1299 | 1307 | pValue->nData = nValue; |
| 1300 | 1308 | |
| 1301 | 1309 | return TH_OK; |
| 1302 | 1310 | } |
| 1303 | 1311 | |
| @@ -1412,11 +1420,11 @@ | ||
| 1412 | 1420 | char *zRes; |
| 1413 | 1421 | if( n<0 ){ |
| 1414 | 1422 | n = th_strlen(z); |
| 1415 | 1423 | } |
| 1416 | 1424 | zRes = Th_Malloc(interp, n+1); |
| 1417 | - memcpy(zRes, z, n); | |
| 1425 | + th_memcpy(zRes, z, n); | |
| 1418 | 1426 | zRes[n] = '\0'; |
| 1419 | 1427 | return zRes; |
| 1420 | 1428 | } |
| 1421 | 1429 | |
| 1422 | 1430 | /* |
| @@ -1472,11 +1480,11 @@ | ||
| 1472 | 1480 | } |
| 1473 | 1481 | |
| 1474 | 1482 | if( z && n>0 ){ |
| 1475 | 1483 | char *zResult; |
| 1476 | 1484 | zResult = Th_Malloc(pInterp, n+1); |
| 1477 | - memcpy(zResult, z, n); | |
| 1485 | + th_memcpy(zResult, z, n); | |
| 1478 | 1486 | zResult[n] = '\0'; |
| 1479 | 1487 | pInterp->zResult = zResult; |
| 1480 | 1488 | pInterp->nResult = n; |
| 1481 | 1489 | } |
| 1482 | 1490 | |
| @@ -1775,12 +1783,12 @@ | ||
| 1775 | 1783 | nElem = th_strlen(zElem); |
| 1776 | 1784 | } |
| 1777 | 1785 | |
| 1778 | 1786 | nNew = *pnStr + nElem; |
| 1779 | 1787 | zNew = Th_Malloc(interp, nNew); |
| 1780 | - memcpy(zNew, *pzStr, *pnStr); | |
| 1781 | - memcpy(&zNew[*pnStr], zElem, nElem); | |
| 1788 | + th_memcpy(zNew, *pzStr, *pnStr); | |
| 1789 | + th_memcpy(&zNew[*pnStr], zElem, nElem); | |
| 1782 | 1790 | |
| 1783 | 1791 | Th_Free(interp, *pzStr); |
| 1784 | 1792 | *pzStr = zNew; |
| 1785 | 1793 | *pnStr = nNew; |
| 1786 | 1794 | |
| @@ -2335,18 +2343,18 @@ | ||
| 2335 | 2343 | if( pNew->pOp || pNew->nValue ){ |
| 2336 | 2344 | if( pNew->nValue ){ |
| 2337 | 2345 | /* A terminal. Copy the string value. */ |
| 2338 | 2346 | assert( !pNew->pOp ); |
| 2339 | 2347 | pNew->zValue = Th_Malloc(interp, pNew->nValue); |
| 2340 | - memcpy(pNew->zValue, z, pNew->nValue); | |
| 2348 | + th_memcpy(pNew->zValue, z, pNew->nValue); | |
| 2341 | 2349 | i += pNew->nValue; |
| 2342 | 2350 | } |
| 2343 | 2351 | if( (nToken%16)==0 ){ |
| 2344 | 2352 | /* Grow the apToken array. */ |
| 2345 | 2353 | Expr **apTokenOld = apToken; |
| 2346 | 2354 | apToken = Th_Malloc(interp, sizeof(Expr *)*(nToken+16)); |
| 2347 | - memcpy(apToken, apTokenOld, sizeof(Expr *)*nToken); | |
| 2355 | + th_memcpy(apToken, apTokenOld, sizeof(Expr *)*nToken); | |
| 2348 | 2356 | } |
| 2349 | 2357 | |
| 2350 | 2358 | /* Put the new token at the end of the apToken array */ |
| 2351 | 2359 | apToken[nToken] = pNew; |
| 2352 | 2360 | nToken++; |
| @@ -2513,11 +2521,11 @@ | ||
| 2513 | 2521 | |
| 2514 | 2522 | if( op>0 && !pRet ){ |
| 2515 | 2523 | pRet = (Th_HashEntry *)Th_Malloc(interp, sizeof(Th_HashEntry) + nKey); |
| 2516 | 2524 | pRet->zKey = (char *)&pRet[1]; |
| 2517 | 2525 | pRet->nKey = nKey; |
| 2518 | - memcpy(pRet->zKey, zKey, nKey); | |
| 2526 | + th_memcpy(pRet->zKey, zKey, nKey); | |
| 2519 | 2527 | pRet->pNext = pHash->a[iKey]; |
| 2520 | 2528 | pHash->a[iKey] = pRet; |
| 2521 | 2529 | } |
| 2522 | 2530 | |
| 2523 | 2531 | return pRet; |
| 2524 | 2532 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -202,10 +202,18 @@ | |
| 202 | }; |
| 203 | typedef struct Buffer Buffer; |
| 204 | static int thBufferWrite(Th_Interp *interp, Buffer *, const char *, int); |
| 205 | static void thBufferInit(Buffer *); |
| 206 | static void thBufferFree(Th_Interp *interp, Buffer *); |
| 207 | |
| 208 | /* |
| 209 | ** Append nAdd bytes of content copied from zAdd to the end of buffer |
| 210 | ** pBuffer. If there is not enough space currently allocated, resize |
| 211 | ** the allocation to make space. |
| @@ -227,17 +235,17 @@ | |
| 227 | char *zNew; |
| 228 | int nNew; |
| 229 | |
| 230 | nNew = nReq*2; |
| 231 | zNew = (char *)Th_Malloc(interp, nNew); |
| 232 | memcpy(zNew, pBuffer->zBuf, pBuffer->nBuf); |
| 233 | Th_Free(interp, pBuffer->zBuf); |
| 234 | pBuffer->nBufAlloc = nNew; |
| 235 | pBuffer->zBuf = zNew; |
| 236 | } |
| 237 | |
| 238 | memcpy(&pBuffer->zBuf[pBuffer->nBuf], zAdd, nAdd); |
| 239 | pBuffer->nBuf += nAdd; |
| 240 | pBuffer->zBuf[pBuffer->nBuf] = '\0'; |
| 241 | |
| 242 | return TH_OK; |
| 243 | } |
| @@ -841,12 +849,12 @@ | |
| 841 | sizeof(int) * nCount + /* anElem */ |
| 842 | strbuf.nBuf /* space for list element strings */ |
| 843 | ); |
| 844 | anElem = (int *)&azElem[nCount]; |
| 845 | zElem = (char *)&anElem[nCount]; |
| 846 | memcpy(anElem, lenbuf.zBuf, lenbuf.nBuf); |
| 847 | memcpy(zElem, strbuf.zBuf, strbuf.nBuf); |
| 848 | for(i=0; i<nCount;i++){ |
| 849 | azElem[i] = zElem; |
| 850 | zElem += (anElem[i] + 1); |
| 851 | } |
| 852 | *pazElem = azElem; |
| @@ -1293,11 +1301,11 @@ | |
| 1293 | } |
| 1294 | |
| 1295 | assert(zValue || nValue==0); |
| 1296 | pValue->zData = Th_Malloc(interp, nValue+1); |
| 1297 | pValue->zData[nValue] = '\0'; |
| 1298 | memcpy(pValue->zData, zValue, nValue); |
| 1299 | pValue->nData = nValue; |
| 1300 | |
| 1301 | return TH_OK; |
| 1302 | } |
| 1303 | |
| @@ -1412,11 +1420,11 @@ | |
| 1412 | char *zRes; |
| 1413 | if( n<0 ){ |
| 1414 | n = th_strlen(z); |
| 1415 | } |
| 1416 | zRes = Th_Malloc(interp, n+1); |
| 1417 | memcpy(zRes, z, n); |
| 1418 | zRes[n] = '\0'; |
| 1419 | return zRes; |
| 1420 | } |
| 1421 | |
| 1422 | /* |
| @@ -1472,11 +1480,11 @@ | |
| 1472 | } |
| 1473 | |
| 1474 | if( z && n>0 ){ |
| 1475 | char *zResult; |
| 1476 | zResult = Th_Malloc(pInterp, n+1); |
| 1477 | memcpy(zResult, z, n); |
| 1478 | zResult[n] = '\0'; |
| 1479 | pInterp->zResult = zResult; |
| 1480 | pInterp->nResult = n; |
| 1481 | } |
| 1482 | |
| @@ -1775,12 +1783,12 @@ | |
| 1775 | nElem = th_strlen(zElem); |
| 1776 | } |
| 1777 | |
| 1778 | nNew = *pnStr + nElem; |
| 1779 | zNew = Th_Malloc(interp, nNew); |
| 1780 | memcpy(zNew, *pzStr, *pnStr); |
| 1781 | memcpy(&zNew[*pnStr], zElem, nElem); |
| 1782 | |
| 1783 | Th_Free(interp, *pzStr); |
| 1784 | *pzStr = zNew; |
| 1785 | *pnStr = nNew; |
| 1786 | |
| @@ -2335,18 +2343,18 @@ | |
| 2335 | if( pNew->pOp || pNew->nValue ){ |
| 2336 | if( pNew->nValue ){ |
| 2337 | /* A terminal. Copy the string value. */ |
| 2338 | assert( !pNew->pOp ); |
| 2339 | pNew->zValue = Th_Malloc(interp, pNew->nValue); |
| 2340 | memcpy(pNew->zValue, z, pNew->nValue); |
| 2341 | i += pNew->nValue; |
| 2342 | } |
| 2343 | if( (nToken%16)==0 ){ |
| 2344 | /* Grow the apToken array. */ |
| 2345 | Expr **apTokenOld = apToken; |
| 2346 | apToken = Th_Malloc(interp, sizeof(Expr *)*(nToken+16)); |
| 2347 | memcpy(apToken, apTokenOld, sizeof(Expr *)*nToken); |
| 2348 | } |
| 2349 | |
| 2350 | /* Put the new token at the end of the apToken array */ |
| 2351 | apToken[nToken] = pNew; |
| 2352 | nToken++; |
| @@ -2513,11 +2521,11 @@ | |
| 2513 | |
| 2514 | if( op>0 && !pRet ){ |
| 2515 | pRet = (Th_HashEntry *)Th_Malloc(interp, sizeof(Th_HashEntry) + nKey); |
| 2516 | pRet->zKey = (char *)&pRet[1]; |
| 2517 | pRet->nKey = nKey; |
| 2518 | memcpy(pRet->zKey, zKey, nKey); |
| 2519 | pRet->pNext = pHash->a[iKey]; |
| 2520 | pHash->a[iKey] = pRet; |
| 2521 | } |
| 2522 | |
| 2523 | return pRet; |
| 2524 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -202,10 +202,18 @@ | |
| 202 | }; |
| 203 | typedef struct Buffer Buffer; |
| 204 | static int thBufferWrite(Th_Interp *interp, Buffer *, const char *, int); |
| 205 | static void thBufferInit(Buffer *); |
| 206 | static void thBufferFree(Th_Interp *interp, Buffer *); |
| 207 | |
| 208 | /* |
| 209 | ** This version of memcpy() allows the first are second argument to |
| 210 | ** be NULL as long as the number of bytes to copy is zero. |
| 211 | */ |
| 212 | static void *th_memcpy(void *dest, const void *src, size_t n){ |
| 213 | return n>0 ? memcpy(dest,src,n) : dest; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | ** Append nAdd bytes of content copied from zAdd to the end of buffer |
| 218 | ** pBuffer. If there is not enough space currently allocated, resize |
| 219 | ** the allocation to make space. |
| @@ -227,17 +235,17 @@ | |
| 235 | char *zNew; |
| 236 | int nNew; |
| 237 | |
| 238 | nNew = nReq*2; |
| 239 | zNew = (char *)Th_Malloc(interp, nNew); |
| 240 | th_memcpy(zNew, pBuffer->zBuf, pBuffer->nBuf); |
| 241 | Th_Free(interp, pBuffer->zBuf); |
| 242 | pBuffer->nBufAlloc = nNew; |
| 243 | pBuffer->zBuf = zNew; |
| 244 | } |
| 245 | |
| 246 | th_memcpy(&pBuffer->zBuf[pBuffer->nBuf], zAdd, nAdd); |
| 247 | pBuffer->nBuf += nAdd; |
| 248 | pBuffer->zBuf[pBuffer->nBuf] = '\0'; |
| 249 | |
| 250 | return TH_OK; |
| 251 | } |
| @@ -841,12 +849,12 @@ | |
| 849 | sizeof(int) * nCount + /* anElem */ |
| 850 | strbuf.nBuf /* space for list element strings */ |
| 851 | ); |
| 852 | anElem = (int *)&azElem[nCount]; |
| 853 | zElem = (char *)&anElem[nCount]; |
| 854 | th_memcpy(anElem, lenbuf.zBuf, lenbuf.nBuf); |
| 855 | th_memcpy(zElem, strbuf.zBuf, strbuf.nBuf); |
| 856 | for(i=0; i<nCount;i++){ |
| 857 | azElem[i] = zElem; |
| 858 | zElem += (anElem[i] + 1); |
| 859 | } |
| 860 | *pazElem = azElem; |
| @@ -1293,11 +1301,11 @@ | |
| 1301 | } |
| 1302 | |
| 1303 | assert(zValue || nValue==0); |
| 1304 | pValue->zData = Th_Malloc(interp, nValue+1); |
| 1305 | pValue->zData[nValue] = '\0'; |
| 1306 | th_memcpy(pValue->zData, zValue, nValue); |
| 1307 | pValue->nData = nValue; |
| 1308 | |
| 1309 | return TH_OK; |
| 1310 | } |
| 1311 | |
| @@ -1412,11 +1420,11 @@ | |
| 1420 | char *zRes; |
| 1421 | if( n<0 ){ |
| 1422 | n = th_strlen(z); |
| 1423 | } |
| 1424 | zRes = Th_Malloc(interp, n+1); |
| 1425 | th_memcpy(zRes, z, n); |
| 1426 | zRes[n] = '\0'; |
| 1427 | return zRes; |
| 1428 | } |
| 1429 | |
| 1430 | /* |
| @@ -1472,11 +1480,11 @@ | |
| 1480 | } |
| 1481 | |
| 1482 | if( z && n>0 ){ |
| 1483 | char *zResult; |
| 1484 | zResult = Th_Malloc(pInterp, n+1); |
| 1485 | th_memcpy(zResult, z, n); |
| 1486 | zResult[n] = '\0'; |
| 1487 | pInterp->zResult = zResult; |
| 1488 | pInterp->nResult = n; |
| 1489 | } |
| 1490 | |
| @@ -1775,12 +1783,12 @@ | |
| 1783 | nElem = th_strlen(zElem); |
| 1784 | } |
| 1785 | |
| 1786 | nNew = *pnStr + nElem; |
| 1787 | zNew = Th_Malloc(interp, nNew); |
| 1788 | th_memcpy(zNew, *pzStr, *pnStr); |
| 1789 | th_memcpy(&zNew[*pnStr], zElem, nElem); |
| 1790 | |
| 1791 | Th_Free(interp, *pzStr); |
| 1792 | *pzStr = zNew; |
| 1793 | *pnStr = nNew; |
| 1794 | |
| @@ -2335,18 +2343,18 @@ | |
| 2343 | if( pNew->pOp || pNew->nValue ){ |
| 2344 | if( pNew->nValue ){ |
| 2345 | /* A terminal. Copy the string value. */ |
| 2346 | assert( !pNew->pOp ); |
| 2347 | pNew->zValue = Th_Malloc(interp, pNew->nValue); |
| 2348 | th_memcpy(pNew->zValue, z, pNew->nValue); |
| 2349 | i += pNew->nValue; |
| 2350 | } |
| 2351 | if( (nToken%16)==0 ){ |
| 2352 | /* Grow the apToken array. */ |
| 2353 | Expr **apTokenOld = apToken; |
| 2354 | apToken = Th_Malloc(interp, sizeof(Expr *)*(nToken+16)); |
| 2355 | th_memcpy(apToken, apTokenOld, sizeof(Expr *)*nToken); |
| 2356 | } |
| 2357 | |
| 2358 | /* Put the new token at the end of the apToken array */ |
| 2359 | apToken[nToken] = pNew; |
| 2360 | nToken++; |
| @@ -2513,11 +2521,11 @@ | |
| 2521 | |
| 2522 | if( op>0 && !pRet ){ |
| 2523 | pRet = (Th_HashEntry *)Th_Malloc(interp, sizeof(Th_HashEntry) + nKey); |
| 2524 | pRet->zKey = (char *)&pRet[1]; |
| 2525 | pRet->nKey = nKey; |
| 2526 | th_memcpy(pRet->zKey, zKey, nKey); |
| 2527 | pRet->pNext = pHash->a[iKey]; |
| 2528 | pHash->a[iKey] = pRet; |
| 2529 | } |
| 2530 | |
| 2531 | return pRet; |
| 2532 |