contributed by < terry23304
>
用 INIT_LIST_HEAD
初始化 list head
pre-commit hook 告知 memory leak ,查了一下才發現strdup
可能會 malloc
失敗
remove: 斷開節點之間的鏈結,還存在記憶體中
注意用語: 「節點」
:notes: jserv
如果 src 字元數(含'\0')比 bufsize 少,會把剩下未滿 bufsize 的部分通通補上 '\0'
如果 src 字元數(含'\0')比 bufsize 多,要自己補 '\0'
想問為甚麼 q_remove_head 要用 sp
儲存被移除的值
是為了讓 q_insert_head 申請 memory 的速度更快嗎,但 q_insert_head 的 parameter 也沒有記憶體位置
將問題列在下方開發紀錄,並詳述你的疑慮,避免只說「儲存被移除的值」,應該具體指出相關程式碼,附上你的推測和實驗。
:notes: jserv
The reason for copying the string value to sp is that the value member of the element_t struct is an internal implementation detail of the linked list and is not intended to be accessed or modified directly by the caller of the q_remove_head function.
By providing a sp buffer as an argument to the function, the caller can obtain the string value of the removed element in a way that is safe and consistent with the function's API.
忘記是 doublly-linked list ,原本 while 判斷式這樣寫會導致 infinite loop
對每個節點檢查是否與下一個節點字串相等,若相等則刪除
原本的寫法在 next == head
的時候 next->value
會出錯,所以改成刪除前一個節點
每兩點交換一次,利用 list_add
與 list_del
來更改節點位置
改成直接用 list_move
將目前節點跟下一個節點互換,程式碼更精簡
把每個 node 移出再加到 head 後面
用 count
來記錄要 revserse 的節點數
反向迭代串列,紀錄最大的字串,若節點字串比最大字串小則移除
原本沒有紀錄 prev
,會導致 segmentation fault (dereferenced a NULL or invalid pointer)
當成單向的串列合併起來做排序後再接回 prev
變回雙向串列
執行後 make test 分數未改變
發現 do_new
會出問題, 參考 yanjiew 的解決方式,把 qtest.c
中 q_quit
第一行的 return true
刪除,讓記憶體釋放正常執行
用兩 class data 做 statistical test ,若兩個 data 的 timing distribution 相等則為 constant time
perform a leakage detection test on execution time.
再執行時期用兩類 data 測試兩個 timing distribution is statistically different or not.
first clas: fixed to a constant value
might be chosen to trigger certain special corner-case(e.g. low weight input in arthmetic operations)
low weight input: 較小的數值通常可以使用較少的位元(或較小的數據類型)來表示。使用較小的數據類型可以節省記憶體使用和運算時間,因此可以提高計算效率。
如計算 5 + 1000000,可以將 5 表示為一個 8 位元的整數(如 unsigned char),而將 1000000 表示為一個 32 位元或 64 位元的整數(如 unsigned int 或 unsigned long long)。
second class: chosen at randomfor each measturement
現代處理器提供 cycle counter,可以更準確的測量執行時間
為了最小化環境變化帶來的影響,每項測試隨機選擇 class
再做統計分析前可對各個 measurement 進行一些後處理
第三步是應用統計檢驗來嘗試否定 NULL Hypothesis “兩個 timing distribution 相等”,
統計檢驗方法:
參考 KHLee529 的方法
在論文中的 post-processing 中有提到可以裁減或刪除過大的 measurement ,而在 dudect/constant.c 中的實作是頭尾少做 DROP_SIZE 次測量 cycle 數,要改成排序執行時間後把前後 DROP_SIZE 個執行時間去除後再比較分布
原本只把選出來的 node 移到串列最後,但用 qtest shuffle 了幾次感覺不夠亂
把移到最後改成跟 Fisher–Yates shuffle algo
一樣交換亂數到的節點與最後的節點
參考 do_merge 及 do_reservse_K
在 do_descend、do_merge 等有做檢查是否正確執行函式功能的函式才需要 return ok
make test 達到 100 分後 github action 還是會卡在 Run webfactory/ssh-agent@v0.7.0 ,參考 commit 紀錄後加上 continue-on-error: true
就可以看到皮卡丘