* xmlBufBackToBuffer: * @buf: new buffer wrapping the old one * * Function to be called once internal processing had been done to * update back the buffer provided by the user. This can lead to * a failure in case the size accumulated in the xmlBuf is larger * than what an xmlBuffer can support on 64 bits (INT_MAX) * The xmlBufPtr @buf wrapper is deallocated by this call in any case. * *
| 865 | * Returns the old xmlBufferPtr unless the call failed and NULL is returned |
| 866 | */ |
| 867 | xmlBufferPtr |
| 868 | xmlBufBackToBuffer(xmlBufPtr buf) { |
| 869 | xmlBufferPtr ret; |
| 870 | |
| 871 | if (buf == NULL) |
| 872 | return(NULL); |
| 873 | CHECK_COMPAT(buf) |
| 874 | ret = buf->buffer; |
| 875 | |
| 876 | if ((buf->error) || (ret == NULL)) { |
| 877 | xmlBufFree(buf); |
| 878 | if (ret != NULL) { |
| 879 | ret->content = NULL; |
| 880 | ret->contentIO = NULL; |
| 881 | ret->use = 0; |
| 882 | ret->size = 0; |
| 883 | } |
| 884 | return(NULL); |
| 885 | } |
| 886 | |
| 887 | /* |
| 888 | * What to do in case of error in the buffer ??? |
| 889 | */ |
| 890 | if (buf->use > INT_MAX) { |
| 891 | /* |
| 892 | * Worse case, we really allocated and used more than the |
| 893 | * maximum allowed memory for an xmlBuffer on this architecture. |
| 894 | * Keep the buffer but provide a truncated size value. |
| 895 | */ |
| 896 | xmlBufOverflowError(buf); |
| 897 | ret->use = INT_MAX; |
| 898 | ret->size = INT_MAX; |
| 899 | } else if (buf->size > INT_MAX) { |
| 900 | /* |
| 901 | * milder case, we allocated more than the maximum allowed memory |
| 902 | * for an xmlBuffer on this architecture, but used less than the |
| 903 | * limit. |
| 904 | * Keep the buffer but provide a truncated size value. |
| 905 | */ |
| 906 | xmlBufOverflowError(buf); |
| 907 | ret->use = buf->use; |
| 908 | ret->size = INT_MAX; |
| 909 | } else { |
| 910 | ret->use = buf->use; |
| 911 | ret->size = buf->size; |
| 912 | } |
| 913 | ret->alloc = buf->alloc; |
| 914 | ret->content = buf->content; |
| 915 | ret->contentIO = buf->contentIO; |
| 916 | xmlFree(buf); |
| 917 | return(ret); |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * xmlBufResetInput: |
no test coverage detected