7

I have a diff file I created. I try to apply it on another branch with patch -p1 --dry-run < ~/patch_name (I'm in the 1st directory - hence -p1), but I get

patch: **** malformed patch at line 45: diff --FILE_LOCATION...

Before that error appeared, those line were printed;

checking file file_a
checking file file_b

So, I understand that file_a, file_b are ok and that I have a problem in line 45, so I deleted lines 45 to end-of-file (I did it 2 times - once without a new-line in the end, once with).

Now the error is

patch: **** malformed patch at line 44: diff --FILE_LOCATION...

What's wrong with this patch?

This is the patch itself:

diff --git a/trunk/rf_iss/ISS/code/future/inc/params.h b/trunk/rf_iss/ISS/code/future/inc/params.h
index 1983556..16a8375 100755
--- a/trunk/rf_iss/ISS/code/future/inc/params.h
+++ b/trunk/rf_iss/ISS/code/future/inc/params.h
@@ -2348,6 +2348,7 @@ typedef UINT1 tLocalPortList [CONTEXT_PORT_LIST_SIZE];
 #define MAX_SLI_SLL_NODES               1500
 #define MAX_SLI_BUFF_BLOCKS             2
 #define MAX_SLI_FD_ARR_BLOCKS           2
+#define MAX_SLI_WAKEUP                  25
 #define MAX_SLI_SDT_BLOCKS              MAX_NO_OF_SOCKETS
 #define MAX_SLI_RAW_HASH_NODES          MAX_NO_OF_SOCKETS
 #define MAX_SLI_RAW_RCV_Q_NODES         MAX_NO_OF_SOCKETS
diff --git a/trunk/rf_iss/ISS/code/future/netip/fsip/udp/src/udptskmg.c b/trunk/rf_iss/ISS/code/future/netip/fsip/udp/src/udptskmg.c
index 9db6034..c5ac3ad 100755
--- a/trunk/rf_iss/ISS/code/future/netip/fsip/udp/src/udptskmg.c
+++ b/trunk/rf_iss/ISS/code/future/netip/fsip/udp/src/udptskmg.c
@@ -11,6 +11,7 @@

 static VOID Udp_timer_expiry_handler PROTO ((VOID));
 extern tMemPoolId   gUdp4MemPoolId;
+extern INT4         gi4SelectWakeupFd;
 /*-------------------------------------------------------------------+
  * Function           : Ip_Udp_Task_Init
  *
@@ -191,6 +192,20 @@ udp_task_enqueue_to_applications_in_cxt (UINT4 u4ContextId, UINT2 u2Port,
                                          t_UDP * pUdpHdr)
 {
     t_UDP_TO_APP_MSG_PARMS *pParms = NULL;
+
+    /* If queue is depleting reserved wakeupFd blocks drop packet */
+    if (pCtrlBlk->i4SockDesc != gi4SelectWakeupFd)
+    {
+       if (MemGetFreeUnits (gUdp4MemPoolId) <= MAX_SLI_WAKEUP)
+       {
+           IP_CXT_TRC (u4ContextId, UDP_MOD_TRC,
+                    ALL_FAILURE_TRC | CONTROL_PLANE_TRC, UDP_NAME,
+                    "Packet Discarded since memory goes over reserved wakeup fd's\n");
+           IP_RELEASE_BUF (pBuf, FALSE);
+           return IP_FAILURE;
+       }
+    }

     pParms = (t_UDP_TO_APP_MSG_PARMS *) MemAllocMemBlk (gUdp4MemPoolId);
     if (pParms == NULL)
diff --git a/trunk/rf_iss/ISS/code/future/sli/socket.c b/trunk/rf_iss/ISS/code/future/sli/socket.c
index 1ca5641..2ad721f 100755
--- a/trunk/rf_iss/ISS/code/future/sli/socket.c
+++ b/trunk/rf_iss/ISS/code/future/sli/socket.c
@@ -3244,6 +3244,26 @@ SliSendtoWithTrace (INT4 i4SockDesc, CONST VOID *pi1Buf, INT4 i4BufLen,
             }
             cpPeerSdtSock = SOCK_DESC_TABLE[i4PeerSockDesc];

+            /* check added to ensure that MAX_SLI_WAKEUP 
+             * units are reserved for WakeupFD socket. This is to 
+             * ensure wakeup fd is always protected such that once
+             * it gets notification, it will cleanup the filled
+             * udp queue. but wakeup fd could
+             * not be triggered because of lack of space in queue
+             * so explicitly reserve space for wakeup fd socket.
+             */
+            if (i4SockDesc != gi4SelectWakeupFd)
+            {
+                if (MemGetFreeUnits (gUdp4MemPoolId) <= MAX_SLI_WAKEUP)
+                {
+                     SLI_Release_Buffer (pBufChnHdr, FALSE);
+                     CpsdtSock->i1ErrorCode = SLI_EMEMFAIL;
+                     SLI_ERR (SLI_EMEMFAIL);
+                     GiveSliProtectSem(CpsdtSock->ProtectSemId);
+                     return SLI_FAILURE;
+                }
+            }
+ 
             /* allocate memory for UDP message from UDP4 mem pool */
             pParms = (t_UDP_TO_APP_MSG_PARMS *) MemAllocMemBlk (gUdp4MemPoolId);
             if (pParms == NULL)

I created it using diff so I don't understand how could it be malformed...

2
  • 1
    I have no crystal ball. Your patch violates the expected format somehow, e.g. no space before unchanged lines. Provide the patch with your question, if you need a better answer. :-)
    – mvw
    Jan 7, 2018 at 13:27
  • @mvw I added the patch (not long ~70 lines) Jan 8, 2018 at 7:26

3 Answers 3

15

I recently ran into this issue myself when manually editing a patch file becaused it contained some undesired changes.

Here is where the issue lies (I've added line numbers to illustrate):

@@ -191,6 +192,20 @@ udp_task_enqueue_to_applications_in_cxt (UINT4 u4ContextId, UINT2 u2Port,
1                                          t_UDP * pUdpHdr)
2 {
3     t_UDP_TO_APP_MSG_PARMS *pParms = NULL;
4+
5+    /* If queue is depleting reserved wakeupFd blocks drop packet */
6+    if (pCtrlBlk->i4SockDesc != gi4SelectWakeupFd)
7+    {
8+       if (MemGetFreeUnits (gUdp4MemPoolId) <= MAX_SLI_WAKEUP)
9+       {
10+           IP_CXT_TRC (u4ContextId, UDP_MOD_TRC,
11+                    ALL_FAILURE_TRC | CONTROL_PLANE_TRC, UDP_NAME,
12+                    "Packet Discarded since memory goes over reserved wakeup fd's\n");
13+           IP_RELEASE_BUF (pBuf, FALSE);
14+           return IP_FAILURE;
15+       }
16+    }
17
18    pParms = (t_UDP_TO_APP_MSG_PARMS *) MemAllocMemBlk (gUdp4MemPoolId);
19    if (pParms == NULL)

Specifically, the issue lies in "+192,20"

Patch is expecting the final patched hunk to be 20 lines long, but if you count the 6 context lines, plus the 13 added lines, minus the 0 removals, this only adds up to 19. As you'll notice, the line after if (pParms == NULL) happens to be line 45, which is the line number listed in the error message - it reached line 45 expecting one more line in the hunk, but instead received a line declaring a new hunk.

If you change the first line to

@@ -191,6 +192,19 @@ udp_task_enqueue_to_applications_in_cxt (UINT4 u4ContextId, UINT2 u2Port,

Your patch should apply properly.

1
  • If you ever try to manually edit a delta when working through git add -p, it says in the delta text that if you see an insertion with a "+" prefix you can omit it by just deleting the line. If you see a deletion with a "-" prefix you can keep the line by changing the "-" to a space. But it's certain that this interactive workflow requires a more lenient parse of the delta than patch does, or else it would be too difficult. On the other hand patch should be demanding. Apr 15, 2020 at 23:15
7

rediff does the work for you.

See verbose explanation from here:

https://stackoverflow.com/a/34431351

1

Increasing the maximum fuzz factor did the work for me:

patch -p1 -F 10 < file.patch

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .